DODODO Posted September 6, 2017 Posted September 6, 2017 What am I not understanding? When I run the sample code from the help file to read a text file it never seems to reach the end of the file. I'm using the below code and the only thing it writes to the console is 1 line of the log file and I never see EOF written to the console. I know it's me but I can't suss it out :-( $file = FileOpen("C:\temp\log.log", 0) ; Check if file opened for reading OK If $file = -1 Then MsgBox(0, "Error", "Unable to open file.") Exit EndIf ; Read in lines of text until the EOF is reached While 1 $line = FileReadLine($file) If @error = -1 Then ExitLoop ConsoleWrite("Line read:" & $line) Wend ConsoleWrite("EOF") FileClose($file)
SlackerAl Posted September 6, 2017 Posted September 6, 2017 (edited) I see from the help file: @error: 1 = if file not opened in read mode or other error So do you have the correct path and privs for the file to open? Edit: Add a trap for @error = 1 to see if that is the problem Edited September 6, 2017 by SlackerAl Problem solving step 1: Write a simple, self-contained, running, replicator of your problem.
DODODO Posted September 6, 2017 Author Posted September 6, 2017 yes, it lists out a line from the file so defo can find/open it
SlackerAl Posted September 6, 2017 Posted September 6, 2017 I changed my code to this (I do not have console access) : $file = FileOpen("C:\temp\log.log", 0) ; Check if file opened for reading OK If $file = -1 Then MsgBox(0, "Error", "Unable to open file.") Exit EndIf ; Read in lines of text until the EOF is reached While 1 $line = FileReadLine($file) If @error = -1 Then ExitLoop MsgBox(4096, "read", $line, 10) Wend MsgBox(4096, "finished", @error, 10) FileClose($file) I made C:\temp\log.log containing two lines: test 1 test 2 This ran exactly as I would have expected. Two lines then error -1. What does it do for you? Problem solving step 1: Write a simple, self-contained, running, replicator of your problem.
TheDcoder Posted September 6, 2017 Posted September 6, 2017 $file = FileOpen("C:\temp\log.log", 0) ; Check if file opened for reading OK If $file = -1 Then MsgBox(0, "Error", "Unable to open file.") Exit EndIf ; Read in lines of text until the EOF is reached While 1 $line = FileReadLine($file) If @error = -1 Then ExitLoop If @error Then MsgBox(0, "Error", "FileReadLine has set @error to: " & @error) ConsoleWrite("Line read:" & $line) Wend ConsoleWrite("EOF") FileClose($file) Try this code and see if you catch an error message EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time) DcodingTheWeb Forum - Follow for updates and Join for discussion
DODODO Posted September 6, 2017 Author Posted September 6, 2017 OK, i copy and pasted your example and it works. Which is odd as mine didn't, so am wondering if it is a simple copy/paste error. Thanks for the assist!
LarsJ Posted September 6, 2017 Posted September 6, 2017 EOF is reached in the code in first post. Simply add " & @CRLF " (without quotation marks) immediately before the end parenthesis in the ConsoleWrite statements. Controls, File Explorer, ROT objects, UI Automation, Windows Message MonitorCompiled code: Accessing AutoIt variables, DotNet.au3 UDF, Using C# and VB codeShell menus: The Context menu, The Favorites menu. Shell related: Control Panel, System Image ListsGraphics related: Rubik's Cube, OpenGL without external libraries, Navigating in an image, Non-rectangular selectionsListView controls: Colors and fonts, Multi-line header, Multi-line items, Checkboxes and icons, Incremental searchListView controls: Virtual ListViews, Editing cells, Data display functions
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