Jump to content

FileRead help!!


hamad12
 Share

Recommended Posts

I've a simple question regarding reading a txt file

I'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 script

2012-01-29 09:19:08 : done

etc etc

what 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 like

Local $chars = FileRead($file, 10)

    MsgBox(0, "Char read:", $chars)

can you please help me how to read the last line?

Edited by hamad12
Link to comment
Share on other sites

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)
Link to comment
Share on other sites

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

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 by hamad12
Link to comment
Share on other sites

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 by Beege
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...