Wednesday, February 9, 2011

Create a text file example

'create a text file example
On Error Resume Next
dim objFSO
dim objFile

'specify filename and path for file to create
strFile="c:\file.txt"
set objFSO=CreateObject("Scripting.FileSystemObject")
'if file already exists, value of TRUE forces overwriting file
set objFile=objFSO.CreateTextFile(strFile,TRUE)
objFile.WriteLine "This is an entry into my logfile"
'write 3 blank lines
objFile.WriteBlankLines(3)
objFile.WriteLine "Here is the last line of my logfile"
wscript.Echo "See " & strFile & " for results"
'close file
objFile.Close
set objFSO=Nothing
set objFile=Nothing

No comments: