Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


Writing to the top of a file (textStream)

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,1043
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Writing to the top of a file (textStream)
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 Writing to the top of a file (textStream) - 6/7/2004 6:12:25 PM   
  makubex

 

Posts: 1
Score: 0
Joined: 6/7/2004
From:
Status: offline
I am writing a VBscript that powers a commenting system.
From a webpage, it gets the users input and then i want it to write to a log file of some sort. At the same time, when the page loads, the page will displays the content of the log file, with the latest entry displayed at the top.

How do i do this? When i write to the log file, i can only write to the bottom, is there any way to write to the top?
 
 
Post #: 1
 
 Re: Writing to the top of a file (textStream) - 6/9/2004 6:27:40 AM   
  mbouchard


Posts: 1916
Score: 16
Joined: 5/15/2003
From: USA
Status: offline
quote:
When i write to the log file, i can only write to the bottom

This is how VBscript behaves by default. The only way around that is to use variables and/or temp file.

Lets hope that I can explain these correctly. If you have any questions, please let me know

log1 (original file)
log2 (temp file)

1) Read log1.txt into a variable
Set f = fso.OpenTextFile("c:\log1.txt", ForReading)
ReadAllTextFile = f.ReadAll

Overwrite log1.txt with the new log info and then append everything in ReadAllTextFile to log1.txt

2) Use a temp file:
Rename log1.txt to log2.txt
Have the webpage recreate log1.txt with the new log info
Read log2.txt using the readall method
Append to log1.txt
Delete log2.txt

(in reply to makubex)
 
 
Post #: 2
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Writing to the top of a file (textStream) Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts