Quantcast
Channel: AutoIt v3 - General Help and Support
Viewing all articles
Browse latest Browse all 12506

Reading text files, testing @error

$
0
0

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)

Viewing all articles
Browse latest Browse all 12506

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>