SublimePorte Posted May 11, 2010 Posted May 11, 2010 I am trying to read a file line by line from the end.According to docs:[optional] The line number to read. The first line of a text file is line 1 (not zero), last line is -1.One would assume that -2 would be the second last line and so on, yet it doesn't appear to be the case.Any way to read a file line by line from the end?
99ojo Posted May 11, 2010 Posted May 11, 2010 (edited) Hi, #include <file.au3> ;file to open $file = "test.txt" ;open file in read mode $filehnd = FileOpen ($file, 0) ;loop reading lastline to first line For $i = _FileCountLines ($file) To 1 Step - 1 $line = FileReadLine ($filehnd, $i) MsgBox (0,"",$line) Next FileClose($file) ;-)) Stefan @edit: Array solution: #include <file.au3> Global $arlines $file = "test.txt" _FileReadToArray ($file, $arlines) For $i = $arlines [0] To 1 Step - 1 MsgBox (0,"", $arlines [$i]) Next Edited May 11, 2010 by 99ojo
SublimePorte Posted May 11, 2010 Author Posted May 11, 2010 Ahh should've checked the udf's for a function to countlines. Thanks.
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