Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

FSO help

Status
Not open for further replies.

maxpower1

Programmer
Jul 29, 2001
488
US
how can I read the last line in a file? The file is generated by unix's tail command. hence, if something is written to that file, I always just want to retrieve this last line only. Is it possible to do this in javascript using FSO?

thanks
 
This shouldn't be to difficult, basically what you want to do is open the text file into as a TextStream object and then loop through the file one line at a time, saving each line until you reach the end of the stream, whatever value is in your variable when you reach the end of the stream will be the last line:
Code:
<%
Dim fso, f, lastLine
Set fso=Server.CreateObject(&quot;Scripting.FileSystemObject&quot;)
Set f=fso.OpenTextFile(Server.MapPath(&quot;whatever.txt&quot;), 1)

Do Until f.AtEndOfStream = true
lastLine = f.ReadLine
Loop

Response.ContentType = &quot;text/plain&quot;  'only did this so you the content wouldn't be reolved by the browser
Response.Write &quot;The last line was: &quot; & vbCrLf
Response.Write lastLine

f.Close
Set f=Nothing
Set fso=Nothing
%>

-Tarwn --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---
 
Can you open the file using ADO and then use the movelast method on it?

I seem to remember something like that being posted in this forum a few weeks back.
Thanks,

Gabe
 
You probably could do it with ADO, using the Text Provider. There is little to be gained though, and it would be slower than just zipping through the file using FSO as shown above.

If the file gets big it'll be nasty anyhow. At some point this needs to be in a database or some other structure giving fast access to the new entry.

Maybe it doesn't get hit on too often though?
 
Gee, I can't win. I made the same sort of statement as darpankumar in the other thread and got blasted for my thoughts and that ADO was the way to go.

I guess I should just keep my mouth shut.
Thanks,

Gabe
 
I'm not sure which way would be faster, I haven't had a chance to test them on large files yet, though it might be interesting if soeone were to read the file in both manners and let us know which was quicker.
In both cases the object will be reading the entire file so the only thing that should affect the speed is how the actual object connects to the file and reads it.
If I get some free time later i will run a test on my &quot;remove me&quot; email to see which is faster.

Oh, before anyone asks :)
My &quot;remove me&quot; email is the one I bombard peiople with when the first remove me email doesn't remove me from their mailing list. It is 80,000 lines of remove me repeated over and over.
devilgrin.gif


-Tarwn
--- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top