How to create text file and write to it in vbscript

后端 未结 3 1482
长发绾君心
长发绾君心 2020-12-02 02:40

I have the following script which locates all access files on a machine:

strComputer = \".\"

Set objWMIService = GetObject(\"winmgmts:\\\\\" & strComput         


        
3条回答
  •  情歌与酒
    2020-12-02 02:56

    This is what you are looking for. In this part: ("C:\test.txt" ,8 , True), the first parameter is the path to the file. The second parameter is the iomode option. There are three options for the second parameter, 1 means for reading, 2 means for writing, and 8 means for appending. The third parameter is a boolean, true means a new file can be created if it doesn't exist. False means a new file cannot be created.

    Dim FSO
    Set FSO = CreateObject("Scripting.FileSystemObject")
    
    Set OutPutFile = FSO.OpenTextFile("C:\test.txt" ,8 , True)
    OutPutFile.WriteLine("Writing text to a file")
    
    Set FSO= Nothing
    

提交回复
热议问题