kylet90 Posted November 19, 2013 Share Posted November 19, 2013 (edited) ; filename to read $source_file = "C:\testing\*.txt" ; open file to read and store the handle $handle_read = FileOpen($source_file, 0) ; check the handle is valid If $handle_read = -1 Then ; show warning and exit with code 1 MsgBox(0, @ScriptName, 'failed to open handle to read the file') Exit 1 EndIf Hi, I am trying to use the FileOpen command to open a text file but it doesn't work. I tried searching the documentation but I can't see a way to use a wildcard. The actual file name is source.txt, but I plan for this process to repeat so it needs to be capable of reading any text file within that directory (there will only be one, at the end of the script I will have the file move to a complete folder). Thanks Edited November 19, 2013 by kylet90 Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted November 19, 2013 Moderators Share Posted November 19, 2013 kylet90,You cannot use wildcards with FileOpen - as it returns a handle it can only deal with one file at a time. So I suggest you use _FileListToArray (which does accept wildcards) to get the filename so that you can use it. 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...
kylet90 Posted November 19, 2013 Author Share Posted November 19, 2013 #include <File.au3> #include <Array.au3> ; filename to read $path = "C:\testing\" $source_file = _FileListToArray($path, "*", 1) ; open file to read and store the handle $handle_read = FileOpen($source_file, 0) ; check the handle is valid If $handle_read = -1 Then ; show warning and exit with code 1 ;MsgBox(0, @ScriptName, 'failed to open handle to read the file') MsgBox(0, "Message", $source_file) I'm obviously doing it wrong, can you shed any light on my mistake? Link to comment Share on other sites More sharing options...
Moderators Solution Melba23 Posted November 19, 2013 Moderators Solution Share Posted November 19, 2013 kylet90,_FileListToArray returns (as it name suggests) an array - so you have to use the correct syntax to access it. This reads a file in the script folder named "Lines.txt (I already had it in place because I was working on your other problem earlier): #include <File.au3> #include <Array.au3> #include <Constants.au3> ; filename to read $path = @ScriptDir & "\" $source_file = _FileListToArray($path, "*.txt", 1) ; Check we have a return If Not @error Then ; open file to read and store the handle - you said only 1 file so it must be index [1] $handle_read = FileOpen($path & $source_file[1], 0) ; check the handle is valid If $handle_read = -1 Then ; show warning and exit with code 1 MsgBox(0, @ScriptName, 'failed to open handle to read the file') Exit EndIf MsgBox($MB_SYSTEMMODAL, "Read", FileRead($handle_read)) FileClose($handle_read) EndIfPlease ask if you still have questions. 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...
kylet90 Posted November 19, 2013 Author Share Posted November 19, 2013 Thanks a lot for the help. It was invaluable to the progression of my script! Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted November 19, 2013 Moderators Share Posted November 19, 2013 kylet90,Glad I could help. 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...
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