SublimePorte 0 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? Share this post Link to post Share on other sites
99ojo 0 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 Share this post Link to post Share on other sites
SublimePorte 0 Posted May 11, 2010 Ahh should've checked the udf's for a function to countlines. Thanks. Share this post Link to post Share on other sites