国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > VBScript > 正文

VBScript 文件操作代碼小結

2020-07-26 11:53:22
字體:
來源:轉載
供稿:網友

創建文本文件

復制代碼 代碼如下:

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

一行行的讀取文本文件內容
復制代碼 代碼如下:

Const ForReading = 1
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile ("c:/scripts/servers.txt", ForReading)
Do Until objTextFile.AtEndOfStream
strComputer = objTextFile.ReadLine
Wscript.Echo strComputer
Loop
objTextFile.Close

追加文本文件一行內容
復制代碼 代碼如下:

Const ForAppending = 8
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile ("C:/Scripts/Service_Status.txt", ForAppending, True)
objTextFile.WriteLine("追加的內容")
objTextFile.Close

有用的幾個函數:
替換:將Jim替換成James。
復制代碼 代碼如下:

strNewText = Replace(strText, "Jim ", "James ")

用逗號分隔字符串:
復制代碼 代碼如下:

arrpath=split(strDN,",")
wscript.echo arrpath(0)

幾個實例:
讀取文本文件指定的行內容(讀第四行內容存到strLine變量中)
復制代碼 代碼如下:

Const ForReading = 1
Set objFSO = CreateObject("Scripting.FileSystemObject") Set objTextFile = objFSO.OpenTextFile("mylogfile.log", ForReading)
For i = 1 to 3 objTextFile.ReadLine Next
strLine = objTextFile.ReadLine Wscript.Echo strLine
objTextFile.Close

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 景德镇市| 闸北区| 宜阳县| 浙江省| 策勒县| 涿鹿县| 靖宇县| 祥云县| 武汉市| 铜梁县| 乐至县| 宣化县| 安图县| 浑源县| 北票市| 河东区| 汝南县| 通榆县| 资源县| 沈阳市| 修文县| 连平县| 芮城县| 甘洛县| 新巴尔虎左旗| 汝阳县| 清新县| 济宁市| 青铜峡市| 驻马店市| 洪湖市| 依安县| 宝应县| 澄江县| 河北省| 万州区| 当阳市| 临泽县| 元朗区| 杭锦后旗| 新郑市|