VBScript 文件操作代碼小結 軟件測試
創建文本文件
復制代碼 代碼如下:
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.CreateTextFile("C:\FSO\ScriptLog.txt")
檢察文件是否存在
復制代碼 代碼如下:
Set objFSO = CreateObject("Scripting.FileSystemObject")
If objFSO.FileExists("C:\FSO\ScriptLog.txt") Then
Set objFolder = objFSO.GetFile("C:\FSO\ScriptLog.txt")
Else
Wscript.Echo "File does not exist."
End If
刪除文本文件
復制代碼 代碼如下:
Set objFSO = CreateObject("Scripting.FileSystemObject")
objFSO.DeleteFile("C:\FSO\ScriptLog.txt")
重命名文件
復制代碼 代碼如下:
Set objFSO = CreateObject("Scripting.FileSystemObject")
objFSO.MoveFile "C:\FSO\ScriptLog.txt" , "C:\FSO\BackupLog.txt"
文本操作
讀取全部內容
復制代碼 代碼如下:
Const ForReading = 1
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("C:\Scripts\Test.txt", ForReading)
strContents = objFile.ReadAll
objFile.Close
一行行的讀取文本文件內容
文章來源于領測軟件測試網 http://www.kjueaiud.com/