Friday, November 19, 2010

VBScript Code - Appends a text to file

Write the below code in a notepad and save it as a .vbs file. Either run it from command prompt or run it by double-clicking on it.

VBScript Code - Appends a text to a file. If the file does not exist, it creates the file.


Const ForReading = 1, ForWriting = 2, ForAppending = 8
Set FSO = CreateObject("Scripting.FilesystemObject")
Set filetxt = FSO.OpenTextFile("c:\myfile.txt", ForAppending, True)
filetxt.WriteLine("Myfirst line of text.")
filetxt.Close