Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default FileSystemObject to get last 10 lines of text file.

Hi there,

I am interested in finding out how to read the last 10 lines (or so) of a
text file using the FileSystemObject function, rather than looping through a
text file line-by-line until the end is reached then working backwards.

I may be looking at reading the last 10 lines of a large text file almost
every second, and would be interested in the fastest method available.

If anyone can explain how this could be done, I'd be very grateful!

Thank you.



  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,824
Default FileSystemObject to get last 10 lines of text file.

I searched google in the *scripting* newsgroup and found this:

http://groups.google.com/groups?thre...%40tkmsftngp10

The last post in the thread contained this:

This code takes 4 seconds to get last 10 lines out of 221,000 Lines regdmp
File.



john wrote:

Hi there,

I am interested in finding out how to read the last 10 lines (or so) of a
text file using the FileSystemObject function, rather than looping through a
text file line-by-line until the end is reached then working backwards.

I may be looking at reading the last 10 lines of a large text file almost
every second, and would be interested in the fastest method available.

If anyone can explain how this could be done, I'd be very grateful!

Thank you.


--

Dave Peterson

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default FileSystemObject to get last 10 lines of text file.

I guess that is about 3 second too long <g

Regards,
Tom Ogilvy


Dave Peterson wrote in message
...
I searched google in the *scripting* newsgroup and found this:

http://groups.google.com/groups?thre...%40tkmsftngp10

The last post in the thread contained this:

This code takes 4 seconds to get last 10 lines out of 221,000 Lines regdmp
File.






  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default FileSystemObject to get last 10 lines of text file.

Hi Dave,

Thanks for the link.

I gave the code a quick go (Excel) and it fell flat on it's face. Before I
go asking how to make it work, were you pointing to this code as a 'how to'
within VBA, or an indication as to the results using that approach?

If there are no HUGE benefits from the FileSystemObject, then the File Line
# method is probably the quickest/appropriate direction, yes? (Although I
stepped through a procedure and watched it go over and over till it got to
the last line:(

To explain a little further (Hi Tom): The file in question is a logfile that
updates by adding a few extra lines of data each time an action/change is
made within a -browser based- application (which I cannot gain access to or
control). The section (Say 10 lines detailing Log-off time) I'm interested
in catching, is appended when the application closes/logs off.

I have looked into detecting the Findwindow (title) to detect when the
application isn't in use, as a bases to either check the logfile, or record
a time when the application was stopped... But that was a no go, as the
application is itself appears to be running within an application and whats
worse, the window title doesn't change even when a different role is being
performed within that application... Thats right, it's a horrible situation!

So I'm back to looking at the end of the log-file every time a change occurs
within the application, which funnily enough, I can detect via the FileDate
change function to detect file properties.

Now that I've wrote out all the negatives, I bet I've also convinced you I'm
on a looser!

Thanks again!

Dave Peterson wrote in message
...
I searched google in the *scripting* newsgroup and found this:

http://groups.google.com/groups?thre...%40tkmsftngp10

The last post in the thread contained this:

This code takes 4 seconds to get last 10 lines out of 221,000 Lines regdmp
File.



john wrote:

Hi there,

I am interested in finding out how to read the last 10 lines (or so) of

a
text file using the FileSystemObject function, rather than looping

through a
text file line-by-line until the end is reached then working backwards.

I may be looking at reading the last 10 lines of a large text file

almost
every second, and would be interested in the fastest method available.

If anyone can explain how this could be done, I'd be very grateful!

Thank you.


--

Dave Peterson



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,824
Default FileSystemObject to get last 10 lines of text file.

Does the last line mean wscript.echo? If yes, then this is the equivalent of a
msgbox. It was there to show the that the data was retrieved--not to be used in
real life?

If you're checking lots of times just to see if there are changes, then maybe
you could use an API that watches for changes.

Randy Birch's VBNet site has some code that uses API calls to watch a folder.
Try http://www.mvps.org/vbnet

look for: FindChangeNotification

john wrote:

Hi Dave,

Thanks for the link.

I gave the code a quick go (Excel) and it fell flat on it's face. Before I
go asking how to make it work, were you pointing to this code as a 'how to'
within VBA, or an indication as to the results using that approach?

If there are no HUGE benefits from the FileSystemObject, then the File Line
# method is probably the quickest/appropriate direction, yes? (Although I
stepped through a procedure and watched it go over and over till it got to
the last line:(

To explain a little further (Hi Tom): The file in question is a logfile that
updates by adding a few extra lines of data each time an action/change is
made within a -browser based- application (which I cannot gain access to or
control). The section (Say 10 lines detailing Log-off time) I'm interested
in catching, is appended when the application closes/logs off.

I have looked into detecting the Findwindow (title) to detect when the
application isn't in use, as a bases to either check the logfile, or record
a time when the application was stopped... But that was a no go, as the
application is itself appears to be running within an application and whats
worse, the window title doesn't change even when a different role is being
performed within that application... Thats right, it's a horrible situation!

So I'm back to looking at the end of the log-file every time a change occurs
within the application, which funnily enough, I can detect via the FileDate
change function to detect file properties.

Now that I've wrote out all the negatives, I bet I've also convinced you I'm
on a looser!

Thanks again!

Dave Peterson wrote in message
...
I searched google in the *scripting* newsgroup and found this:

http://groups.google.com/groups?thre...%40tkmsftngp10

The last post in the thread contained this:

This code takes 4 seconds to get last 10 lines out of 221,000 Lines regdmp
File.



john wrote:

Hi there,

I am interested in finding out how to read the last 10 lines (or so) of

a
text file using the FileSystemObject function, rather than looping

through a
text file line-by-line until the end is reached then working backwards.

I may be looking at reading the last 10 lines of a large text file

almost
every second, and would be interested in the fastest method available.

If anyone can explain how this could be done, I'd be very grateful!

Thank you.


--

Dave Peterson


--

Dave Peterson



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 13
Default FileSystemObject to get last 10 lines of text file.


John,

I've been looking at the variuous posts here and there are some great
ideas. In the past, I've used the one with the Skip method posted by Dana.
Are you writing the log? If so, have you considered making your log a fixed
record length and using vb random file access. You could do a direct seek
to the 10th record from the end. Random access would be the fastest way to
go. Another possibily is to log to a DB table instead of a file.

Thanks,

Jim

Jim Vita
Microsoft Developer Support

This posting is provided "AS IS" with no warranties, and confers no rights.

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default FileSystemObject to get last 10 lines of text file.

Hi Jim,

You are right, the suggestion and feedback has been tremendous, don't get me
wrong. I'm grateful! I was just looking for the quickest method... As to
your question, unfortunately I'm not creating the log file as such, at least
I don't have the control to do as you suggest. Thanks for pointing that out
tho!

It made me think that maybe I could Link this information somehow? The
linking facility in Excel, returns an icon (rather than the text file
contents), which is about as useful as something not very useful!

Maybe Access has more power to deal with such requests. I'm not a big fan of
Access but it could probably handle the same objective, maybe better seeing
as it's Data, not calculations...

I'll go poke the Access.groups then.

Thanks

Jim Vita wrote in message
...

John,

I've been looking at the variuous posts here and there are some great
ideas. In the past, I've used the one with the Skip method posted by Dana.
Are you writing the log? If so, have you considered making your log a

fixed
record length and using vb random file access. You could do a direct seek
to the 10th record from the end. Random access would be the fastest way to
go. Another possibily is to log to a DB table instead of a file.

Thanks,

Jim

Jim Vita
Microsoft Developer Support

This posting is provided "AS IS" with no warranties, and confers no

rights.



  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 13
Default FileSystemObject to get last 10 lines of text file.


John,

I've been doing a little more poking on your problem. I know your're doing
VB but C++ has the abiliity manipulate file pointer in a way that VB can't.
I've been playing with some C++ code that is really fast. I created a
500,000 record / 80 character file. The time to read the last 10 records is
unmeasurable (it calculates to 0.00000000). The trick in this code is that
you can't specify a number of records from the end. You have to specify a
file offset from the end in bytes. However, it automatically syncs itself
to the first full record following the offset point you select. Now, you
can't use C++ directly but you could write a standard DLL wrapper around
the function and include it in VB with a Declare Function. You could also
create a COM wrapper around it. Would you like me to post it?

Thanks,

Jim

Jim Vita
Microsoft Developer Support

This posting is provided "AS IS" with no warranties, and confers no rights.

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to read all lines from a text file into cells C10:Cxxx ? Claudia d'Amato Excel Discussion (Misc queries) 1 September 22nd 09 01:11 PM
Copying certain lines from a text file Michael A Excel Discussion (Misc queries) 3 February 13th 07 08:08 PM
text box insert in Excel - text box lines print on second copy Diana (Berry & Co) Excel Discussion (Misc queries) 0 July 26th 06 04:39 AM
Some lines of text in Excel field do not wrap text. Please help. Michele Excel Discussion (Misc queries) 0 January 5th 06 07:27 PM
Scripting.FileSystemObject Leif Rasmussen Excel Discussion (Misc queries) 1 January 12th 05 11:21 PM


All times are GMT +1. The time now is 09:23 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"