Read and write into a file using VBScript

前端 未结 9 1449
轮回少年
轮回少年 2020-11-27 06:34

How can we read and write some string into a text file using VBScript? I mean I have a text file which is already present so when I use this code below:-

Set         


        
9条回答
  •  醉梦人生
    2020-11-27 07:01

    You could also read the entire file in, and store it in an array

    Set filestreamIN = CreateObject("Scripting.FileSystemObject").OpenTextFile("C:\Test.txt",1)
    file = Split(filestreamIN.ReadAll(), vbCrLf)
    filestreamIN.Close()
    Set filestreamIN = Nothing
    

    Manipulate the array in any way you choose, and then write the array back to the file.

    Set filestreamOUT = CreateObject("Scripting.FileSystemObject").OpenTextFile("C:\Test.txt",2,true)
    
    for i = LBound(file) to UBound(file)
        filestreamOUT.WriteLine(file(i))
    Next
    
    filestreamOUT.Close()
    Set filestreamOUT = Nothing 
    

提交回复
热议问题