ExElNeT Posted September 27, 2006 Posted September 27, 2006 I am trying to read the last line of a .txt file everytime a new line gets inserted by another program in the .txt file. I ve tried this: #include <File.au3> $file = FileOpen("test.txt", 0) ; Check if file opened for reading OK If $file = -1 Then MsgBox(0, "Error", "Unable to open file.") Exit EndIf $lineCount = _FileCountLines("test.txt") $line = FileReadLine($file, $lineCount) If @error = -1 Then ExitLoop; end of file If @error = 1 Then MsgBox(0,"error","Cannot read line") EndIf MsgBox(0,"LineCount", $lineCount & ' ' & $line) FileClose($file) But the output is wrong. The output line is not the last line in the .txt file thanks in advance
Ted at Miles Posted September 27, 2006 Posted September 27, 2006 I am trying to read the last line of a .txt file everytime a new line gets inserted by another program in the .txt file. I ve tried this: #include <File.au3> $file = FileOpen("test.txt", 0) ; Check if file opened for reading OK If $file = -1 Then MsgBox(0, "Error", "Unable to open file.") Exit EndIf $lineCount = _FileCountLines("test.txt") $line = FileReadLine($file, $lineCount) If @error = -1 Then ExitLoop; end of file If @error = 1 Then MsgBox(0,"error","Cannot read line") EndIf MsgBox(0,"LineCount", $lineCount & ' ' & $line) FileClose($file) But the output is wrong. The output line is not the last line in the .txt file thanks in advance
Ted at Miles Posted September 27, 2006 Posted September 27, 2006 I have messed with the line count command. Does not work most of the time. It is supposed to work for server logs from what I have heard. good luck
ExElNeT Posted September 27, 2006 Author Posted September 27, 2006 I have messed with the line count command. Does not work most of the time. It is supposed to work for server logs from what I have heard. good luckthe line number is correct. but the output doesnt match that.
Moderators SmOke_N Posted September 27, 2006 Moderators Posted September 27, 2006 (edited) $aSplit = StringSplit(StringStripCR(FileRead('FileLocation.Name')), @LF) MsgBox(64, 'Last Line', $aSplit[$aSplit[0]]) Edited September 27, 2006 by SmOke_N Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.
randallc Posted September 27, 2006 Posted September 27, 2006 Hi, or, if you do not want to read a huge file and want quicker, try my "tailRW.au3" [link in signature] or wrap tail.exe. Best, Randall ExcelCOM... AccessCom.. Word2... FileListToArrayNew...SearchMiner... Regexps...SQL...Explorer...Array2D.. _GUIListView...array problem...APITailRW
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