Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

Reading File in Backwards
Hi,

I have a text file which I would like to read from the end and display only
a certain number of records. Is there any way of doing this?

Thanks,
Shahid



Report this thread to moderator Post Follow-up to this message
Old Post
Shahid Juma
12-23-04 08:55 PM


Re: Reading File in Backwards
InStrRev()


--
Curt Christianson
Owner/Lead Developer, DF-Software
Site: http://www.Darkfalz.com
Blog: http://blog.Darkfalz.com


"Shahid Juma" <shahid319REMOVETHIS@hotmail.com> wrote in message
news:ufsrvBS6EHA.1120@TK2MSFTNGP11.phx.gbl...
> Hi,
>
> I have a text file which I would like to read from the end and display
> only
> a certain number of records. Is there any way of doing this?
>
> Thanks,
> Shahid
>
>



Report this thread to moderator Post Follow-up to this message
Old Post
Curt_C [MVP]
12-23-04 08:55 PM


Re: Reading File in Backwards
Doesn't this function just return the last occurence? I am not doing a
search, what I want to do is read the last entry in the file and backwards
towards the top....

Shahid

"Curt_C [MVP]" <software_AT_darkfalz.com> wrote in message
news:uwvt2CS6EHA.2552@TK2MSFTNGP09.phx.gbl...
> InStrRev()
>
>
> --
> Curt Christianson
> Owner/Lead Developer, DF-Software
> Site: http://www.Darkfalz.com
> Blog: http://blog.Darkfalz.com
>
>
> "Shahid Juma" <shahid319REMOVETHIS@hotmail.com> wrote in message
> news:ufsrvBS6EHA.1120@TK2MSFTNGP11.phx.gbl... 
>
>



Report this thread to moderator Post Follow-up to this message
Old Post
Shahid Juma
12-23-04 08:55 PM


Re: Reading File in Backwards
How large is the file?  If not too big then you might consider reading in
the entire file, doing a split on newline and then taking the last entries
in the resulting array.

Tim.


"Shahid Juma" <shahid319REMOVETHIS@hotmail.com> wrote in message
news:ufsrvBS6EHA.1120@TK2MSFTNGP11.phx.gbl...
> Hi,
>
> I have a text file which I would like to read from the end and display
only
> a certain number of records. Is there any way of doing this?
>
> Thanks,
> Shahid
>
>



Report this thread to moderator Post Follow-up to this message
Old Post
Tim Williams
12-23-04 08:55 PM


Re: Reading File in Backwards
<%
Const fRead = 1, fWrite = 2, fAppend = 8
Dim objFSO, objIStream
Dim strLine, strPrintLine, strFile
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
strFile = Server.MapPath("thefile.txt")
Set objIStream = objFSO.OpenTextFDile(strFile, fRead, False)
Do While NOT objIStream.AtEndOfStream
strLine = objIStream.ReadLine
strPrintLine = strLine + "<br/>" + strPrintLine
iCounter = iCounter + 1
Loop
objIStream.Close
Set objIStream = Nothing
Set objFSO = Nothing
Response.Write strPrintLine
%>

--

Regards

Steven Burn
Ur I.T. Mate Group
www.it-mate.co.uk

Keeping it FREE!


"Shahid Juma" <shahid319REMOVETHIS@hotmail.com> wrote in message
news:OZjPfIS6EHA.3700@tk2msftngp13.phx.gbl...
> Doesn't this function just return the last occurence? I am not doing a
> search, what I want to do is read the last entry in the file and backwards
> towards the top....
>
> Shahid
>
> "Curt_C [MVP]" <software_AT_darkfalz.com> wrote in message
> news:uwvt2CS6EHA.2552@TK2MSFTNGP09.phx.gbl... 
>
>



Report this thread to moderator Post Follow-up to this message
Old Post
Steven Burn
12-23-04 08:55 PM


Re: Reading File in Backwards
Is there a seperator in the file? space, comma, etc?
If so just use Split and loop backwards through the array

--
Curt Christianson
Owner/Lead Developer, DF-Software
Site: http://www.Darkfalz.com
Blog: http://blog.Darkfalz.com


"Shahid Juma" <shahid319REMOVETHIS@hotmail.com> wrote in message
news:OZjPfIS6EHA.3700@tk2msftngp13.phx.gbl...
> Doesn't this function just return the last occurence? I am not doing a
> search, what I want to do is read the last entry in the file and backwards
> towards the top....
>
> Shahid
>
> "Curt_C [MVP]" <software_AT_darkfalz.com> wrote in message
> news:uwvt2CS6EHA.2552@TK2MSFTNGP09.phx.gbl... 
>
>



Report this thread to moderator Post Follow-up to this message
Old Post
Curt_C [MVP]
12-24-04 01:55 AM


Re: Reading File in Backwards
Shahid Juma wrote:
> I have a text file which I would like to read from the end and
> display only a certain number of records. Is there any way of doing
> this?

I assume you don't want to reverse the contents of each line, but rather the
order of the lines:
var fso = Server.CreateObject("Scripting.FileSystemObject"),
src = fso.OpenTextFile("YourSourceFile.txt").ReadAll(),
rows = src.split("\r\n").reverse()

At this point, you can either write the text file back:
fso.CreateTextFile("Output.txt",true).Write(rows.join("\r\n"))

Or display it online:
<TABLE><TR><TD><%=rows.join("</TD><TR><TR><TD>")%></TD></TR></TABLE>


To get the last 10 lines only, modify the [rows] assignment:
rows = src.split("\r\n").slice(-10).reverse()


FileSystemObject
http://msdn.microsoft.com/library/e...br />
ence.asp
Array.join()
http://msdn.microsoft.com/library/e...56jsmthjoin.asp
Array.reverse()
http://msdn.microsoft.com/library/e...smthreverse.asp
Array.slice()
http://msdn.microsoft.com/library/e...6jsmthsplit.asp


--
Dave Anderson

Unsolicited commercial email will be read at a cost of $500 per message. Use
of this email address implies consent to these terms. Please do not contact
me directly or ask me to contact you directly for assistance. If your
question is worth asking, it's worth posting.



Report this thread to moderator Post Follow-up to this message
Old Post
Dave Anderson
12-24-04 01:55 AM


Re: Reading File in Backwards
I wrote:
> FileSystemObject
>
http://msdn.microsoft.com/library/e...ay.j
oin()
>
http://msdn.microsoft.com/library/e...spArray.reverse()[colo
r=darkred]
>[/color]
http://msdn.microsoft.com/library/e...y.sl
ice()...

For some reason, OE-QuoteFix did the above (though it looks fine in the
source). It should look like this:

FileSystemObject
http://msdn.microsoft.com/library/e...br />
ence.asp

Array.join()
http://msdn.microsoft.com/library/e...56jsmthjoin.asp

Array.reverse()
http://msdn.microsoft.com/library/e...smthreverse.asp

Array.slice()
http://msdn.microsoft.com/library/e...6jsmthsplit.asp



--
Dave Anderson

Unsolicited commercial email will be read at a cost of $500 per message. Use
of this email address implies consent to these terms. Please do not contact
me directly or ask me to contact you directly for assistance. If your
question is worth asking, it's worth posting.




Report this thread to moderator Post Follow-up to this message
Old Post
Dave Anderson
12-24-04 01:55 AM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

ASP archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 08:03 AM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.