Is it possible to create a file and write lines to it in vbscript?Something similar to echo in bat file (echo something something >>sometextfile.txt).On execution of the vbscript depending on the path of the script would create an autorun.inf file to execute a particular program (\smartdriverbackup\sdb.exe).Also how can I strip/remove the drive letter from the complete file path?
+1
A:
You'll need to deal with File System Object
. See this OpenTextFile
method sample.
Rubens Farias
2010-02-04 10:15:15
A:
Set objFSO=CreateObject("Scripting.FileSystemObject")
' How to write file
outFile="c:\test\autorun.inf"
Set objFile = objFSO.CreateTextFile(outFile,True)
objFile.Write "test string" & vbCrLf
objFile.Close
'How to read a file
strFile = "c:\test\file"
Set objFile = objFS.OpenTextFile(strFile)
Do Until objFile.AtEndOfStream
strLine= objFile.ReadLine
Wscript.Echo strLine
Loop
objFile.Close
'to get file path without drive letter, assuming drive letters are c:, d:, etc
strFile="c:\test\file"
s = Split(strFile,":")
WScript.Echo s(1)
ghostdog74
2010-02-04 10:43:23
Thanks ghostdog74 for the answer I have tried the script.It works.I need to put it into actual application.
Dario Dias
2010-02-04 11:00:26
I have problem in writing a text line with inverted commas,Eg: This is a "Test" "String".Besides iF I want a variable value to be written in inverted commas I cant.
Dario Dias
2010-02-06 10:10:50
you have to escape the quotes. try `""""`
ghostdog74
2010-02-06 10:25:24
how exactly do I escape the quotes?
Dario Dias
2010-02-06 11:01:38
do a `Wscript.Echo """"Test""""` and see.
ghostdog74
2010-02-06 11:19:17
tried,does not work
Dario Dias
2010-02-06 11:22:44
see http://tinyurl.com/y9l3l2g
ghostdog74
2010-02-06 11:59:01