Jump to content
Sign in to follow this  
scriptomator

editing .txt files with edit box

Recommended Posts

scriptomator

i am still pretty new to autoit and i need help.Posted Image

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 mean

help.au3

Edited by scriptomator

Share this post


Link to post
Share on other sites
Melba23

scriptomator,

And here is some! :P

I have rewritten your script a fair bit - look for the <<<<<<<<<<<<<<<<< lines to see why I have done what I did:

#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   ;==>readtext

Please ask if anything is unclear. :mellow:

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
scriptomator

Posted ImagePosted ImagePosted ImagePosted ImagePosted ImagePosted ImagePosted Image 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 by scriptomator

Share this post


Link to post
Share on other sites
scriptomator

why does everyone do this?

Func _writetext()

EndFunc ;==>_writetext

Share this post


Link to post
Share on other sites
Mat

why does everyone do this?

Func _writetext()

EndFunc ;==>_writetext

So that you can see what function it is from the end... Makes sense when you have very long functions.

Besides... It's neat :mellow: I know some people who do the same for all blocks, for instance:

If $sTest = "This is a test" Then

EndIf ; $sTest = "This is a test"

Share this post


Link to post
Share on other sites
scriptomator

thanks, it does make sense.

Share this post


Link to post
Share on other sites
scriptomator

For :

Melba23

thanks 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.

#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 by scriptomator

Share this post


Link to post
Share on other sites
Melba23

scriptomator,

Here is my version with a bit of error-checking added - look for the <<<<<<<<<< lines again!

#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. :mellow:

M23

Edit: Reset to @DesktopDir as that is where you wanted it.

Edited by Melba23

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites
scriptomator

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 by scriptomator

Share this post


Link to post
Share on other sites
scriptomator

i added functionality to the delete, and i also added a list all files button( which i originally wanted in the script) to the script

i also made it look nicePosted Image

#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 ;==>findallfiles

I would like to know how to list all of the files without the .txt at the end

Edited by scriptomator

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×