| | |
|
Active Server Pages help tutorial how to ASP Help ASP Tutorials ASP Programming ASP Code - ASP Free CJWSoft ASPProtect ASPBanner ASPClassifieds
(Advanced)
(Components)
(Database)
(General)
(Vbscript)

|
|
Subject: |
Re: Need help with writing Text Files! |
From: |
Pete |
Date: |
3/9/1999 7:46:44 AM |
IP: |
193.133.140.50 |
To do what you asking you would first have to create a new file, write you new line to that file and then write the oldfile to the botton of it. I assume that you would want to have the new file have the same name as the old one so I've shown how to rename them by copying the files back over. I don't use the FileSystemObject that much myself so this might not work first time, for instance you may have to reopen the newfile in append mode when copying the oldfile over to it, have a play around. I learnt all this info from the VBScript site at microsoft : http://msdn.microsoft.com/scripting/default.htm
Heres the code:
' To insert your new line at the top of a file
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Dim fso, oldfile, newfile, renamefile
Set fso = CreateObject("Scripting.FileSystemObject")
Set newfile = fso.OpenTextFile("c:\newfile.txt", 1, ForWriting, True)
newfile.Write "You new 1st line of text"
Set oldfile = fso.OpentextFile("c:\oldfile.txt", ForReading, True)
newfile.Write oldfile.readall
newfile.Close
oldfile.Close
' To over write the old file with the new file
fso.CopyFile "c:\newfile.txt", "c:\oldfile.txt"
fso.DeleteFile "c:\newfile.txt"
Pete |
Previous Message
|
|

|
|
|
|