Reading File in Backwards
Web Server forum
Back To The Forum Home!Search!Private Messaging System

Web Server Talk Web Server Talk > Web Servers reviews > IIS server support > IIS ASP > Reading File in Backwards




  Last Thread   Next Thread Next
  Show Printable Version Email this Page Subscribe to this Thread      Post New Thread    Post A Reply      

    Reading File in Backwards  
Shahid Juma


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
12-23-04 10:59 PM

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







[ Post a follow-up to this message ]



    Re: Reading File in Backwards  
Curt_C [MVP]


Report This Message To A Moderator Edit/Delete Message


 
12-23-04 10:59 PM

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







[ Post a follow-up to this message ]



    Re: Reading File in Backwards  
Shahid Juma


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
12-23-04 10:59 PM

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... 
>
>







[ Post a follow-up to this message ]



    Re: Reading File in Backwards  
Tim Williams


Report This Message To A Moderator Edit/Delete Message


 
12-23-04 10:59 PM

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







[ Post a follow-up to this message ]



    Re: Reading File in Backwards  
Steven Burn


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
12-23-04 10:59 PM

<%
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... 
>
>







[ Post a follow-up to this message ]



    Re: Reading File in Backwards  
Curt_C [MVP]


Report This Message To A Moderator Edit/Delete Message


 
12-23-04 10:59 PM

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... 
>
>







[ Post a follow-up to this message ]



    Re: Reading File in Backwards  
Dave Anderson


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
12-23-04 10:59 PM

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.







[ Post a follow-up to this message ]



    Re: Reading File in Backwards  
Dave Anderson


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
12-23-04 10:59 PM

I wrote:
> FileSystemObject
>
http://msdn.microsoft.com/library/e...ay.jo
in()
>
http://msdn.microsoft.com/library/e...spArray.reverse()[vbcol
=seagreen]
>[/vbcol]
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.








[ Post a follow-up to this message ]



    Sponsored Links  




 





   All times are GMT. The time now is 01:15 PM.      Post New Thread    Post A Reply      
  Last Thread   Next Thread Next


Most Popular forums 

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
 
Medical and Health forum | Computer Games Reviews | Graphics design forum

Back To The Top
Home | Usercp | Faq | Register