Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
468 views
in Technique[技术] by (71.8m points)

vbscript - Creating and writing lines to a file

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 (smartdriverbackupsdb.exe).

Also how can I strip/remove the drive letter from the complete file path?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Set objFSO=CreateObject("Scripting.FileSystemObject")

' How to write file
outFile="c:estautorun.inf"
Set objFile = objFSO.CreateTextFile(outFile,True)
objFile.Write "test string" & vbCrLf
objFile.Close

'How to read a file
strFile = "c:estfile"
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:estfile"
s = Split(strFile,":")
WScript.Echo s(1)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...