scriptomator Posted June 30, 2010 Share Posted June 30, 2010 (edited) i am still pretty new to autoit and i need help.i want to be able to type something into an editbox and press a button that saves the text to a .txt file exactly as typed.And with the same button,be able to load the text of that same .txt file and display it in the editbox for editing.and you can edit different files by typing in the name of the file into another editbox and it loads that file. as it is it does not work the way i want it to.so far the edit part has an uncontrolled loop and the save only saves to a certain point should i have a notepad object in there instead?i will upload a small portion of my script so you can see what i meanhelp.au3 Edited July 3, 2010 by scriptomator Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted June 30, 2010 Moderators Share Posted June 30, 2010 scriptomator,And here is some! I have rewritten your script a fair bit - look for the <<<<<<<<<<<<<<<<< lines to see why I have done what I did:expandcollapse popup#include <GUIConstants.au3> #include <Constants.au3> #include <File.au3> #include <GuiStatusBar.au3> #include <GUIConstantsEx.au3> #include <ButtonConstants.au3> #include <StaticConstants.au3> #include <GuiButton.au3> #include <GuiEdit.au3> #include <WinAPI.au3> #include <AVIConstants.au3> #include <WindowsConstants.au3> #include <TreeViewConstants.au3> HotKeySet("{END}", "abort") ;kills program in case of uncontrolled loop $theone = GUICreate("V4.0", 500, 150, -1, -1) $button1 = GUICtrlCreateButton("(click once) add test.txt", 0, 60, 160, 30) $button11 = GUICtrlCreateButton("Edit", 60, 93, 60, 30) $button12 = GUICtrlCreateButton("Delete", 120, 93, 60, 30) $output = GUICtrlCreateInput("test", 180, 20, 300, 28) ; Input not edit <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< GUICtrlSetFont($output, 14, 510, "", "Candara") $Thebox = GUICtrlCreateEdit("", 180, 50, 300, 100) ; Create it once and then hide/show it <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< GUICtrlSetState($Thebox, $GUI_HIDE) GUISetState() ;FileChangeDir(@ScriptDir) While 1 $msg = GUIGetMsg() Select Case $msg = $button1 If Not FileExists("test.txt") Then $hFile = FileOpen("test.txt", 1) ; Create file only if it does not exist <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< FileClose($hFile) EndIf Case $msg = $button11 If GUICtrlRead($button11) = "Edit" Then ; Why not use buttobn text instead of a flag? <<<<<<<<<<<<<<<<<<<<<<<<<<<< GUICtrlSetData($button11, "Save") ; Use built-in commands - saves on include files <<<<<<<<<<<<<<<<<<<<<<<<<<< GUICtrlSetState($Thebox, $GUI_SHOW) readtext() Else _writetext() GUICtrlSetData($button11, "Edit") ; Use built-in commands - saves on include files <<<<<<<<<<<<<<<<<<<<<<<<<<< GUICtrlSetState($Thebox, $GUI_HIDE) EndIf Case $msg = $button12 MsgBox(0, "info", "this will delete the file typed in the small edit box") GUICtrlSetData($output, "") ; Use built-in commands - saves on include files <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< Case $msg = $GUI_EVENT_CLOSE Exit EndSelect WEnd Func abort() Exit EndFunc ;==>abort Func _writetext() Local $writeto = GUICtrlRead($output) ; read file name in the small editbox so the program can see if it exists Local $worda = FileOpen(@ScriptDir & "\" & $writeto & ".txt", 2) ; Open for writing - overwriting current contents If $worda = -1 Then MsgBox(0, "Error", '"' & $writeto & '"' & " is non existent") Else Local $thecontent = GUICtrlRead($Thebox) ; Why bother to count lines? Just read the whole thing in one go <<<<<<<<<< FileWrite($worda, $thecontent) ; Similarly - write it in one go <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< FileClose($worda) EndIf EndFunc ;==>_writetext Func readtext() Local $writeto = GUICtrlRead($output) Local $words = FileOpen(@ScriptDir & "\" & $writeto & ".txt", 0) If $words = -1 Then MsgBox(0, "Error", '"' & $writeto & '"' & " is non existent") Else Local $thecontent = FileRead($words) ; Why bother to count lines? Just read the whole thing in one go <<<<<<<<<<<<< FileClose($words) GUICtrlSetData($Thebox, $thecontent) ; Use built-in commands - saves on include files <<<<<<<<<<<<<<<<<<<<<<<<<<<<<< GUICtrlSetState($Thebox, $GUI_FOCUS) ; Set the cursot to the edit <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< EndIf EndFunc ;==>readtextPlease ask if anything is unclear. M23  Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area  Link to comment Share on other sites More sharing options...
scriptomator Posted June 30, 2010 Author Share Posted June 30, 2010 (edited) Thanks alot! Idid not know that you could do that with the "filewrite". I looked in the AutoIt3.chm but it was not very clear to me what it could do.I was putting the edit thing off for a long time because i knew it would be hard for me. anyways would you like my full script? it works well but it could probably be shortened. it is a" word maker".this is my script skill improving project if you E-mail me i will E-mail you the link to the file. it has an install to add the needed files. Edited June 30, 2010 by scriptomator Link to comment Share on other sites More sharing options...
scriptomator Posted June 30, 2010 Author Share Posted June 30, 2010 why does everyone do this?Func _writetext()EndFunc ;==>_writetext Link to comment Share on other sites More sharing options...
Mat Posted June 30, 2010 Share Posted June 30, 2010 why does everyone do this?Func _writetext()EndFunc ;==>_writetextSo that you can see what function it is from the end... Makes sense when you have very long functions.Besides... It's neat I know some people who do the same for all blocks, for instance:If $sTest = "This is a test" ThenEndIf ; $sTest = "This is a test" AutoIt Project Listing Link to comment Share on other sites More sharing options...
scriptomator Posted July 1, 2010 Author Share Posted July 1, 2010 thanks, it does make sense. Link to comment Share on other sites More sharing options...
scriptomator Posted July 1, 2010 Author Share Posted July 1, 2010 (edited) For : Melba23thanks for the script again. i found a problem with the script, it makes a new file when you press the save button when there is no file by the name that is entered in the inputbox. but because my program is a lot different than the snippet you made for me a new if...then sequence fixed it. but this is basically what I did. expandcollapse popup#include <GUIConstants.au3> #include <Constants.au3> #include <File.au3> #include <GuiStatusBar.au3> #include <GUIConstantsEx.au3> #include <ButtonConstants.au3> #include <StaticConstants.au3> #include <GuiButton.au3> #include <GuiEdit.au3> #include <WinAPI.au3> #include <AVIConstants.au3> #include <WindowsConstants.au3> #include <TreeViewConstants.au3> HotKeySet("{END}", "abort") ;kills program in case of uncontrolled loop $theone = GUICreate("V4.0", 500, 150, -1, -1) $button1 = GUICtrlCreateButton("(click once) add test.txt", 0, 60, 160, 30) $button11 = GUICtrlCreateButton("Edit", 60, 93, 60, 30) $button12 = GUICtrlCreateButton("Delete", 120, 93, 60, 30) $output = GUICtrlCreateInput("test", 180, 20, 300, 28) ; Input not edit <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< GUICtrlSetFont($output, 14, 510, "", "Candara") $Thebox = GUICtrlCreateEdit("", 180, 50, 300, 100) ; Create it once and then hide/show it <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< GUICtrlSetState($Thebox, $GUI_HIDE) GUISetState() FileChangeDir(@desktopdir) While 1 $msg = GUIGetMsg() Select Case $msg = $button1 If Not FileExists("test.txt") Then $hFile = FileOpen("test.txt", 1) ; Create file only if it does not exist <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< FileClose($hFile) EndIf Case $msg = $button11 If GUICtrlRead($button11) = "Edit" Then ; Why not use buttobn text instead of a flag? <<<<<<<<<<<<<<<<<<<<<<<<<<<< GUICtrlSetData($button11, "Save") ; Use built-in commands - saves on include files <<<<<<<<<<<<<<<<<<<<<<<<<<< GUICtrlSetState($Thebox, $GUI_SHOW) readtext() Else _writetext() GUICtrlSetData($button11, "Edit") ; Use built-in commands - saves on include files <<<<<<<<<<<<<<<<<<<<<<<<<<< GUICtrlSetState($Thebox, $GUI_HIDE) EndIf Case $msg = $button12 MsgBox(0, "info", "this will delete the file typed in the small edit box") GUICtrlSetData($output, "") ; Use built-in commands - saves on include files <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< Case $msg = $GUI_EVENT_CLOSE Exit EndSelect WEnd Func abort() Exit EndFunc ;==>abort Func _writetext() Local $writeto = GUICtrlRead($output) ; read file name in the small editbox so the program can see if it exists Local $worda = FileOpen(@ScriptDir & "\" & $writeto & ".txt", 2) ; Open for writing - overwriting current contents If $worda = -1 Then MsgBox(0, "Error", '"' & $writeto & '"' & " is non existent") Else Local $thecontent = GUICtrlRead($Thebox) ; Why bother to count lines? Just read the whole thing in one go <<<<<<<<<< FileWrite($worda, $thecontent) ; Similarly - write it in one go <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< FileClose($worda) EndIf EndFunc ;==>_writetext Func readtext() Local $writeto = GUICtrlRead($output) Local $words = FileOpen(@ScriptDir & "\" & $writeto & ".txt", 0) If $words = -1 Then GUICtrlSetState($Thebox,$GUI_HIDE) GUICtrlSetData($button11, "Edit") $answer = MsgBox(4, "Error", '"' & $writeto & '"' & " is non existent. do you want to make it?") If $answer = 6 Then GUICtrlSetState($Thebox,$GUI_SHOW) GUICtrlSetData($button11, "Save") _FileCreate($writeto & ".txt") Else EndIf Else Local $thecontent = FileRead($words) ; Why bother to count lines? Just read the whole thing in one go <<<<<<<<<<<<< FileClose($words) GUICtrlSetData($Thebox, $thecontent) ; Use built-in commands - saves on include files <<<<<<<<<<<<<<<<<<<<<<<<<<<<<< GUICtrlSetState($Thebox, $GUI_FOCUS) ; Set the cursot to the edit <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< EndIf EndFunc ;==> i don't know if it can be simpler or scripted better Edited July 1, 2010 by scriptomator Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted July 1, 2010 Moderators Share Posted July 1, 2010 (edited) scriptomator,Here is my version with a bit of error-checking added - look for the <<<<<<<<<< lines again!expandcollapse popup#include <GUIConstants.au3> #include <Constants.au3> #include <File.au3> #include <GuiStatusBar.au3> #include <GUIConstantsEx.au3> #include <ButtonConstants.au3> #include <StaticConstants.au3> #include <GuiButton.au3> #include <GuiEdit.au3> #include <WinAPI.au3> #include <AVIConstants.au3> #include <WindowsConstants.au3> #include <TreeViewConstants.au3> HotKeySet("{END}", "abort") ;kills program in case of uncontrolled loop $theone = GUICreate("V4.0", 500, 150, -1, -1) $button1 = GUICtrlCreateButton("(click once) add test.txt", 0, 60, 160, 30) $button11 = GUICtrlCreateButton("Edit", 60, 93, 60, 30) $button12 = GUICtrlCreateButton("Delete", 120, 93, 60, 30) $output = GUICtrlCreateInput("test", 180, 20, 300, 28) GUICtrlSetFont($output, 14, 510, "", "Candara") $Thebox = GUICtrlCreateEdit("", 180, 50, 300, 100) GUICtrlSetState($Thebox, $GUI_HIDE) GUISetState() FileChangeDir(@DesktopDir) While 1 $msg = GUIGetMsg() Select Case $msg = $button1 If Not FileExists(@DesktopDir & "test.txt") Then $hFile = FileOpen(@DesktopDir & "\test.txt", 1) ; Create file only if it does not exist FileClose($hFile) EndIf Case $msg = $button11 If GUICtrlRead($button11) = "Edit" Then GUICtrlSetData($button11, "Save") GUICtrlSetState($Thebox, $GUI_SHOW) readtext() Else _writetext() GUICtrlSetData($button11, "Edit") GUICtrlSetState($Thebox, $GUI_HIDE) EndIf Case $msg = $button12 MsgBox(0, "info", "this will delete the file typed in the small edit box") GUICtrlSetData($output, "") Case $msg = $GUI_EVENT_CLOSE Exit EndSelect WEnd Func abort() Exit EndFunc ;==>abort Func _writetext() Local $writeto = GUICtrlRead($output) ; Do we have a file name to work with? <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< If $Writeto = "" Then ; Loop until we enter one While GUICtrlRead($output) = "" ; Return and reset the button and edit if Cancel pressed If MsgBox(1, "Error", "You must enter a file name in the small edit box" & @CRLF & "Close this dialog when you have done so") = 2 Then GUICtrlSetData($button11, "Edit") GUICtrlSetState($Thebox, $GUI_HIDE) Return EndIf WEnd $writeto = GUICtrlRead($output) EndIf Local $worda = FileOpen(@DesktopDir & "\" & $writeto & ".txt", 2) ; Open for writing - overwriting current contents ; You have just created the file - if we have an error it is becasue it was not created correctly <<<<<<<<<<<<<<<< If $worda = -1 Then MsgBox(0, "Error", "There was an error opening the file " & @DesktopDir & "\" & $writeto & ".txt") Return EndIf ; The file was opened for writing correctly, so write the contents <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< Local $thecontent = GUICtrlRead($Thebox) FileWrite($worda, $thecontent) FileClose($worda) EndFunc ;==>_writetext Func readtext() Local $writeto = GUICtrlRead($output) ; Do we have a file name to work with? <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< If $Writeto = "" Then ; Loop until we enter one While GUICtrlRead($output) = "" ; Return if Cancel pressed If MsgBox(1, "Error", "You must enter a file name in the small edit box" & @CRLF & "Close this dialog when you have done so") = 2 Then GUICtrlSetState($Thebox,$GUI_HIDE) GUICtrlSetData($button11, "Edit") Return EndIf WEnd $writeto = GUICtrlRead($output) EndIf Local $words = FileOpen(@DesktopDir & "\" & $writeto & ".txt", 0) If $words = -1 Then ; There was a problem opening the file - let us see if it exists <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< If FileExists(@DesktopDir & "\" & $writeto & ".txt") Then ; File exists, so another problem prevented it opening <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< MsgBox(0, "Error", "There was an error opening the file " & @DesktopDir & "\" & $writeto & ".txt") Return Else ; File does not exist, so ask if it should be created <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< If MsgBox(4, "Error", '"' & $writeto & '"' & " is non existent. do you want to make it?") = 6 Then ; Create the file <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< $hFile = FileOpen(@DesktopDir & "\" & $writeto & ".txt", 1) ; Create file only if it does not exist FileClose($hFile) ; Your button and edit box are already in the correct state <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< Else ; There is no file to edit, so reset the button and edit box states <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< GUICtrlSetState($Thebox,$GUI_HIDE) GUICtrlSetData($button11, "Edit") EndIf EndIf Else ; The file was opened so read the contents <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< Local $thecontent = FileRead($words) FileClose($words) GUICtrlSetData($Thebox, $thecontent) GUICtrlSetState($Thebox, $GUI_FOCUS) EndIf EndFunc ;==>Ask if anything is unclear. M23Edit: Reset to @DesktopDir as that is where you wanted it. Edited July 1, 2010 by Melba23  Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area  Link to comment Share on other sites More sharing options...
scriptomator Posted July 2, 2010 Author Share Posted July 2, 2010 (edited) so i am guessing that you like the idea of editing text in your own script, and decided to improve on it. and because of your help with the .txt editor i am finished my script. "Word Maker4.0" and will upload it. so i can now move on to a useful program. "The last calculator you will ever need!" Edited July 2, 2010 by scriptomator Link to comment Share on other sites More sharing options...
scriptomator Posted July 2, 2010 Author Share Posted July 2, 2010 (edited) i added functionality to the delete, and i also added a list all files button( which i originally wanted in the script) to the scripti also made it look niceexpandcollapse popup#include <GUIConstants.au3> #include <Constants.au3> #include <File.au3> #include <GuiStatusBar.au3> #include <GUIConstantsEx.au3> #include <ButtonConstants.au3> #include <StaticConstants.au3> #include <GuiButton.au3> #include <GuiEdit.au3> #include <WinAPI.au3> #include <AVIConstants.au3> #include <WindowsConstants.au3> #include <TreeViewConstants.au3> HotKeySet("{END}", "abort") ;kills program in case of uncontrolled loop $theone = GUICreate("V4.0", 500, 150, -1, -1) $button1 = GUICtrlCreateButton("list all files", 0, 0, 120, 30) $button11 = GUICtrlCreateButton("Edit", 00, 30, 60, 30) $button12 = GUICtrlCreateButton("Delete", 60, 30, 60, 30) $output = GUICtrlCreateInput("test", 120, 0, 380, 28) GUICtrlSetFont($output, 14, 510, "", "Candara") $Thebox = GUICtrlCreateEdit("", 120, 30, 380, 120) GUICtrlSetState($Thebox, $GUI_HIDE) GUISetState() FileChangeDir(@DesktopDir) While 1 $msg = GUIGetMsg() Select Case $msg = $button1 GUICtrlSetData($output,"All Files in Alphabetical Order") _findallfiles() ;i did not put the function here because i don't know if it will clash with the rest of the script and cause it to freese or do an uncontrolled loop GUICtrlSetState($Thebox, $GUI_SHOW) ;If Not FileExists(@DesktopDir & "test.txt") Then ; $hFile = FileOpen(@DesktopDir & "\test.txt", 1) ; Create file only if it does not exist ; FileClose($hFile) ; EndIf Case $msg = $button11 If GUICtrlRead($button11) = "Edit" Then GUICtrlSetData($button11, "Save") GUICtrlSetState($Thebox, $GUI_SHOW) readtext() Else _writetext() GUICtrlSetData($button11, "Edit") GUICtrlSetState($Thebox, $GUI_HIDE) EndIf Case $msg = $button12 MsgBox(0, "info", "this will delete the file typed in the small edit box") $writeto = GUICtrlRead($output) FileDelete(@DesktopDir & "\" & $writeto & ".txt") GUICtrlSetData($output, "") Case $msg = $GUI_EVENT_CLOSE Exit EndSelect WEnd Func abort() Exit EndFunc ;==>abort Func _writetext() Local $writeto = GUICtrlRead($output) ; Do we have a file name to work with? <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< If $Writeto = "" Then ; Loop until we enter one While GUICtrlRead($output) = "" ; Return and reset the button and edit if Cancel pressed If MsgBox(1, "Error", "You must enter a file name in the small edit box" & @CRLF & "Close this dialog when you have done so") = 2 Then GUICtrlSetData($button11, "Edit") GUICtrlSetState($Thebox, $GUI_HIDE) Return EndIf WEnd $writeto = GUICtrlRead($output) EndIf Local $worda = FileOpen(@DesktopDir & "\" & $writeto & ".txt", 2) ; Open for writing - overwriting current contents ; You have just created the file - if we have an error it is becasue it was not created correctly <<<<<<<<<<<<<<<< If $worda = -1 Then MsgBox(0, "Error", "There was an error opening the file " & @DesktopDir & "\" & $writeto & ".txt") Return EndIf ; The file was opened for writing correctly, so write the contents <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< Local $thecontent = GUICtrlRead($Thebox) FileWrite($worda, $thecontent) FileClose($worda) EndFunc ;==>_writetext Func readtext() Local $writeto = GUICtrlRead($output) ; Do we have a file name to work with? <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< If $Writeto = "" Then ; Loop until we enter one While GUICtrlRead($output) = "" ; Return if Cancel pressed If MsgBox(1, "Error", "You must enter a file name in the small edit box" & @CRLF & "Close this dialog when you have done so") = 2 Then GUICtrlSetState($Thebox,$GUI_HIDE) GUICtrlSetData($button11, "Edit") Return EndIf WEnd $writeto = GUICtrlRead($output) EndIf Local $words = FileOpen(@DesktopDir & "\" & $writeto & ".txt", 0) If $words = -1 Then ; There was a problem opening the file - let us see if it exists <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< If FileExists(@DesktopDir & "\" & $writeto & ".txt") Then ; File exists, so another problem prevented it opening <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< MsgBox(0, "Error", "There was an error opening the file " & @DesktopDir & "\" & $writeto & ".txt") Return Else ; File does not exist, so ask if it should be created <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< If MsgBox(4, "Error", '"' & $writeto & '"' & " is non existent. do you want to make it?") = 6 Then ; Create the file <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< $hFile = FileOpen(@DesktopDir & "\" & $writeto & ".txt", 1) ; Create file only if it does not exist FileClose($hFile) ; Your button and edit box are already in the correct state <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< Else ; There is no file to edit, so reset the button and edit box states <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< GUICtrlSetState($Thebox,$GUI_HIDE) GUICtrlSetData($button11, "Edit") EndIf EndIf Else ; The file was opened so read the contents <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< Local $thecontent = FileRead($words) FileClose($words) GUICtrlSetData($Thebox, $thecontent) GUICtrlSetState($Thebox, $GUI_FOCUS) EndIf EndFunc ;==> Func _findallfiles() GUICtrlSetData($Thebox,"") ;erases all charecter in the edotbox $search = FileFindFirstFile("*.txt") ; Check if the search was successful If $search = -1 Then MsgBox(0, "Error", "No files found in current directory") EndIf While 1 ;list all files in current directory with file type .txt until all are found and listed local $fileer = FileFindNextFile($search) If @error Then ExitLoop _GUICtrlEdit_AppendText($Thebox,$fileer & @CRLF) WEnd ; Close the search handle FileClose($search) EndFunc ;==>findallfilesI would like to know how to list all of the files without the .txt at the end Edited July 2, 2010 by scriptomator Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now