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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM