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

首頁 > 編程 > VBScript > 正文

VBScript 文件操作代碼小結

2019-10-26 18:02:53
字體:
來源:轉載
供稿:網友

創建文本文件

復制代碼 代碼如下:

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

您可能感興趣的文章:

使用VBS訪問外部文本文件一些方法和腳本實例代碼vbs刪除文本文件的行的函數用vbs實現讀取文本文件的方法用vbscript實現從文本文件中刪除所有重復行的代碼用vbs對文本文件的內容進行排序用vbs實現對文本文件中的項計數用vbs讀取文本文件的最后一行VBS文本文件操作實現代碼
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表

圖片精選

主站蜘蛛池模板: 湾仔区| 新津县| 宁武县| 辽宁省| 新巴尔虎左旗| 玛纳斯县| 容城县| 年辖:市辖区| 锡林浩特市| 白银市| 常熟市| 谢通门县| 司法| 汤原县| 浦江县| 伊吾县| 萨嘎县| 日照市| 闽侯县| 易门县| 法库县| 东方市| 夏津县| 开阳县| 休宁县| 林西县| 牟定县| 忻州市| 平利县| 兴国县| 都兰县| 长汀县| 遂宁市| 嘉荫县| 灵武市| 沁水县| 通州市| 榆中县| 修水县| 南投县| 深圳市|