File System Object

Results 1 to 2 of 2

Thread: File System Object

  1. #1
    gao Guest

    Default File System Object

    Hi,<BR><BR>Is there an easy way to read out the contents of a text file in the reverse order that it was input.<BR><BR>Let me give you an example:<BR><BR>I have a very simple page with a form. After the form is submitted, the post is dated and stored in a text file, then displayed at the bottom of the same page. I would like to read out the lines in the reverse order so that the latest posts are at the top instead of the bottom which is where they are appended normally.<BR><BR>If anyone has a suggestion (not too difficult one since I am fairly new to asp) on how I might accomplish this, please let me know.<BR><BR>Thanks a bunch!<BR><BR>gao<BR><BR><BR><BR>

  2. #2
    Join Date
    Dec 1969

    Default maybe a better way?

    Possible? Yes.<BR><BR>Good idea? No.<BR><BR>Reason: The only way to do this is to read the entire text file, from start to finish, *EACH TIME*. Can you say sloooowwwwww.<BR><BR>So time to approach it a different way.<BR><BR>How about this:<BR><BR>Keep the last three lines added to the text file in Application variables? Then, when you add another line, just shuffle the lines "up" to make room for the newest line.<BR><BR>Like this:<BR><BR>&#060;%<BR>addedLine = ... same line as was appended to the text file ...<BR><BR>Application.Lock<BR>Application("back2" ) = Application("back1")<BR>Application("back1") = Application("mostRecent")<BR>Application("mostRece nt") = addedLine<BR>Application.Unlock<BR>%&#062;<BR><BR> See it? Now you can display those three lines any time you need by referencing the applicaition values.<BR><BR>But what happens when the server crashes and you need to "seed" those lines to get started again? *NOW* is the time to read the entire text file, saving just the last three lines. Saving them, of course, in those same application values.<BR><BR>How to do that? Something like this:<BR><BR>**** THIS CODE PART OF GLOBAL.ASA and Application_onStart function ****<BR><BR>... I assume you have already set up the FSO and InFile objects ...<BR><BR>line1 = InFile.ReadLine<BR>line2 = InFile.ReadLine<BR><BR>Do Until InFile.atEndOfStream &#039 or is it atEndOfTextStream? whatever...<BR> &nbsp; line1 = line2<BR> &nbsp; line2 = line3<BR> &nbsp; line3 = InFile.ReadLine<BR>Loop<BR><BR>Application("mostRe cent") = line3<BR>Application("back1") = line2<BR>Application("back2") = line1<BR><BR>***********************************<B R><BR>Hokay?<BR><BR><BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts