Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating and writing lines to a file

Tags:

vbscript

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?

like image 231
Dario Dias Avatar asked Feb 04 '10 10:02

Dario Dias


People also ask

How do you write to a file line by line in Python?

To write line by line to a csv file in Python, use either file. write() function or csv. writer() function. The csv.


1 Answers

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) 
like image 63
ghostdog74 Avatar answered Oct 02 '22 13:10

ghostdog74