How to Edit Text in VBS
- 1). Open your favorite text editor.
- 2). Paste the following:
dim FSO, textFile
const ForWriting = 2
const ForAppending = 8
set FSO = CreateObject("Scripting.FileSystemObject")
set textFile = FSO.OpenTextFile("c:\textfile.txt", ForWriting)
textFile.WriteLine "This will overwrite all the current contents of the file and replace it with this sentence."
textFile.Close
set textFile = FSO.OpenTextFile("c:\textfile.txt", ForAppending)
textFile.WriteLine "This will be appended to the end of the file!"
textFile.Close
This declares two constants for two different file input/output modes: ForWriting and ForAppending. If a file is opened with the "ForWriting" flag, then new text will wipe all the current contents of the file. On the other hand, if the "ForAppending" flag is used, the new text will be added to the end of the current file, preserving all its contents. - 3). Save your work. You can run the script by double-clicking it.