AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

FileReadLastLine

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Wish List
View previous topic :: View next topic  
Author Message
CarlosTheTackle



Joined: 19 Oct 2004
Posts: 102

PostPosted: Sat Mar 05, 2005 3:08 am    Post subject: FileReadLastLine Reply with quote

I'm trying to write a very light-weight script that needs to retrieve the last line of a text file of about 400 lines long (though it can vary from much less than that up to about 410). As far I can see, I can't retrieve the last line without retrieving the entire file, either through a Loop, Read or a FileRead followed by a StringSplit, which means my script is not as fast and unintrusive as I would like it.

Would it be possible to have a command like FileReadLastLine, [line number from end] or would AHK still have to internally read the whole thing anyway, making this no faster? I guess it comes down to whether it's possible to determine the total number of lines without parsing the whole thing or not.

Just a thought.

Cheers,
C
Back to top
View user's profile Send private message
jonny



Joined: 13 Nov 2004
Posts: 3004
Location: Minnesota

PostPosted: Sat Mar 05, 2005 4:03 am    Post subject: Reply with quote

Couldn't you just use tail.exe and parse the output?
Back to top
View user's profile Send private message
Chris
Site Admin


Joined: 02 Mar 2004
Posts: 10480

PostPosted: Sat Mar 05, 2005 8:26 am    Post subject: Re: FileReadLastLine Reply with quote

Tail is great for these sort of things, though a file of only 400 lines (unless each line is huge) probably wouldn't benefit that much compared to reading the entire file line by line.

CarlosTheTackle wrote:
whether it's possible to determine the total number of lines without parsing the whole thing or not.
Unless something is known about the file in advance (e.g. that every line is exactly 150 characters long), there is no way to know how many lines are in it without scanning the entire file.

However, programs such as tail.exe use random access to retrieve the last N lines of any file without having to scan the entire thing. Tail.exe doesn't have to know how many lines exist because it searches from the end toward the beginning until it finds the number of lines you specified.

In other words, with tail.exe you know you have the last N lines but you can't know their line numbers unless the file always has the same number of lines in it.
Back to top
View user's profile Send private message Send e-mail
CarlosTheTackle



Joined: 19 Oct 2004
Posts: 102

PostPosted: Sat Mar 05, 2005 10:45 am    Post subject: Reply with quote

jonny wrote:
Couldn't you just use tail.exe and parse the output?

Tail.exe huh. I'll check it out. Thanks

Chris wrote:
In other words, with tail.exe you know you have the last N lines but you can't know their line numbers unless the file always has the same number of lines in it.

Sweet. That's all I need.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Wish List All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group