hamad12 Posted January 29, 2012 Share Posted January 29, 2012 (edited) I've a simple question regarding reading a txt fileI've a file which is basicly a "log file for 1 of the scripts" which is like:2012-01-29 09:13:05 : start: hamad12 started the script2012-01-29 09:19:08 : doneetc etcwhat am trying to do is to read the first10 chars of the LAST LINE? is it possible and how?am already able to read the first 10 chart of the FIRST LINE with something likeLocal $chars = FileRead($file, 10) MsgBox(0, "Char read:", $chars)can you please help me how to read the last line? Edited January 29, 2012 by hamad12 Link to comment Share on other sites More sharing options...
Beege Posted January 29, 2012 Share Posted January 29, 2012 Maybe try using function _FileCountLines() to get the total line count. Then use FileReadLine() read the last line. Then use stringleft() to get the first 10 left most characters of that line. #include <file.au3> $iTotal = _FileCountLines('log.txt') $read = FileReadLine('log.txt', $iTotal) $sFirst_ten = StringLeft($read, 10) Assembly Code: fasmg . fasm . BmpSearch . Au3 Syntax Highlighter . Bounce Multithreading Example . IDispatchASMUDFs: Explorer Frame . ITaskBarList . Scrolling Line Graph . Tray Icon Bar Graph . Explorer Listview . Wiimote . WinSnap . Flicker Free Labels . iTunesPrograms: Ftp Explorer . Snipster . Network Meter . Resistance Calculator Link to comment Share on other sites More sharing options...
Bowmore Posted January 29, 2012 Share Posted January 29, 2012 If the line number parameter in FileReadLine() is negative then the line count is taken from the end of the file. The example Beege gave can be simplified to: #include <file.au3> $sFirst_ten = StringLeft(FileReadLine('log.txt', -1), 10) "Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to build bigger and better idiots. So far, the universe is winning."- Rick Cook Link to comment Share on other sites More sharing options...
Beege Posted January 29, 2012 Share Posted January 29, 2012 Good call. Assembly Code: fasmg . fasm . BmpSearch . Au3 Syntax Highlighter . Bounce Multithreading Example . IDispatchASMUDFs: Explorer Frame . ITaskBarList . Scrolling Line Graph . Tray Icon Bar Graph . Explorer Listview . Wiimote . WinSnap . Flicker Free Labels . iTunesPrograms: Ftp Explorer . Snipster . Network Meter . Resistance Calculator Link to comment Share on other sites More sharing options...
hamad12 Posted January 29, 2012 Author Share Posted January 29, 2012 (edited) If the line number parameter in FileReadLine() is negative then the line count is taken from the end of the file. The example Beege gave can be simplified to: #include <file.au3> $sFirst_ten = StringLeft(FileReadLine('log.txt', -1), 10) Good call. thank you both very much! it's working like a charm silly thing! how to mark the post as solved?? Edited January 29, 2012 by hamad12 Link to comment Share on other sites More sharing options...
Beege Posted January 29, 2012 Share Posted January 29, 2012 (edited) silly thing! how to mark the post as solved??Just go to your first post and click edit, then click "use full editor". The title will be at the top. Just add "<SOLVED>" to the title. I love it when people do this Edited January 29, 2012 by Beege Assembly Code: fasmg . fasm . BmpSearch . Au3 Syntax Highlighter . Bounce Multithreading Example . IDispatchASMUDFs: Explorer Frame . ITaskBarList . Scrolling Line Graph . Tray Icon Bar Graph . Explorer Listview . Wiimote . WinSnap . Flicker Free Labels . iTunesPrograms: Ftp Explorer . Snipster . Network Meter . Resistance Calculator Link to comment Share on other sites More sharing options...
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