How can i make a vbscript type in a text file.

shrshr429

Solid State Member
Messages
19
For example, lets say i have a file example.txt in my Local Drive. What would be the script to write "Hello" in the example.txt file?
 
Dim objFileSystem, objOutputFile
Dim strOutputFile

Const OPEN_FILE_FOR_APPENDING = 8

' generate a filename base on the script name
strOutputFile = "./writefile.out"

Set objFileSystem = CreateObject("Scripting.fileSystemObject")
Set objOutputFile = objFileSystem.OpenTextFile(strOutputFile, _
OPEN_FILE_FOR_APPENDING)

objOutputFile.WriteLine("Hello world (" & Now & ")")
objOutputFile.Close

Set objFileSystem = Nothing

WScript.Quit(0)

I found that, but im not 100% on how it would work. For example if the file was still at c:\example.txt where would i put that in the script?
 
Ah, fair point. It'd go in strOutputFile:
Code:
strOutputFile = "./writefile.out"

The one given there is using the *nix naming convention, if you're on a windows platform just change it accordingly to what you need :)
 
I somewhat figured it out, it'll add text to the file only if it is near it. For example, if the vbs file was located in my documents folder then the text file i am adding has to be there as well. Is there anyway to change it so it will add text to a file in a different location. Anyone?

nevermind figured it out, thanks alot for the link!!
 
Back
Top Bottom