What is the proper way to read text files line by line?
Why the following code doesn't detect end of file?
AutoIt
#include <FileConstants.au3> #include <MsgBoxConstants.au3> Local $sInputFileName = @ScriptDir & "\somefile.xml" Local $LineCount = 0 Local $CharCount = 0 $hInFile = FileOpen($sInputFileName, $FO_READ) While Not @error $sLine = FileReadLine($hInFile) If @error Then ExitLoop $LineCount += 1 $CharCount += StringLen($sLine) WEnd If @error Then MsgBox($MB_OK + $MB_ICONERROR, "File processing", "An error occured when reading the file" & @CRLF & $sInputFileName) Else MsgBox($MB_OK + $MB_ICONINFORMATION, "File processed", "File" & $sInputFileName & @CRLF & "contains " & $LineCount & " lines and " & $CharCount & " characters.") EndIf FileClose($hInFile)