VBS 读写文件

Const fileName = "D:autoSaveParam.txt"

Const Forreading=1
Const ForWriting=2
Const Forappending=8
Dim hP100,hP103,hP105
Dim  Fso ,tf

'the file exists or not
Set Fso = CreateObject("Scripting.FileSystemObject")
If Fso.fileexists(fileName)Then
       'read from file
       Set tf =Fso.opentextfile(fileName,Forreading)
       Do While tf.atendofstream<>True 
            strLine =   tf.ReadLine        
       Loop 

Else 'file not exist
       'create a file and save P paramters into the file
       Set tf=  fso.OpenTextFile(fileName, ForWriting, True)
       tf.writeLine "P105 = 105"
          
End If 
tf.close 
Set Fso =  Nothing

其中,创建一个新的文件,并向文件写入文本也可以用以下方式:

 'create file and write 
  Dim fso,tf
  Set fso =  CreateObject("Scripting.FileSystemObject")
  Set tf = fso.CreateTextFile(strFileName, True) 'True-代表可以被下次写入覆盖

  tf.WriteLine("AABBCC")
  tf.close

参考:https://blog.csdn.net/hc19881010/article/details/5963818?locationNum=15&fps=1

          https://www.docin.com/p-1613338.html

原文地址:https://www.cnblogs.com/small-lazybee/p/13729947.html