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

首頁 > 編程 > VBScript > 正文

vbs操作txt文本文件常用方法與函數代碼

2020-06-26 17:16:20
字體:
來源:轉載
供稿:網友

'creat by 席飛劍(小席老師)

'操作文本文件,操作fso對象(文件對象操作)

函數代碼

創建文件

dim fso, fset fso = server.CreateObject("Scripting.FileSystemObject")set f = fso.CreateTextFile("C:/test.txt", true) '第二個參數表示目標文件存在時是否覆蓋f.Write("寫入內容")f.WriteLine("寫入內容并換行")f.WriteBlankLines(3) '寫入三個空白行(相當于在文本編輯器中按三次回車)f.Close()set f = nothingset fso = nothing

打開并讀文件

dim fso, fset fso = server.CreateObject("Scripting.FileSystemObject")set f = fso.OpenTextFile("C:/test.txt", 1, false) '第二個參數 1 表示只讀打開,第三個參數表示目標文件不存在時是否創建f.Skip(3) '將當前位置向后移三個字符f.SkipLine() '將當前位置移動到下一行的第一個字符,注意:無參數response.Write f.Read(3) '從當前位置向后讀取三個字符,并將當前位置向后移三個字符response.Write f.ReadLine() '從當前位置向后讀取直到遇到換行符(不讀取換行符),并將當前位置移動到下一行的第一個字符,注意:無參數response.Write f.ReadAll() '從當前位置向后讀取,直到文件結束,并將當前位置移動到文件的最后if f.atEndOfLine then  response.Write("一行的結尾!")end ifif f.atEndOfStream then  response.Write("文件的結尾!")end iff.Close()set f = nothingset fso = nothing

打開并寫文件

dim fso, fset fso = server.CreateObject("Scripting.FileSystemObject")set f = fso.OpenTextFile("C:/test.txt", 2, false) '第二個參數 2 表示重寫,如果是 8 表示追加f.Write("寫入內容")f.WriteLine("寫入內容并換行")f.WriteBlankLines(3) '寫入三個空白行(相當于在文本編輯器中按三次回車)f.Close()set f = nothingset fso = nothing

判斷文件是否存在

dim fsoset fso = server.CreateObject("Scripting.FileSystemObject")if fso.FileExists("C:/test.txt") then  response.Write("目標文件存在")else  response.Write("目標文件不存在")end ifset fso = nothing

移動文件

dim fsoset fso = server.CreateObject("Scripting.FileSystemObject")call fso.MoveFile("C:/test.txt", "D:/test111.txt") '兩個參數的文件名部分可以不同set fso = nothing

復制文件

dim fsoset fso = server.CreateObject("Scripting.FileSystemObject")call fso.CopyFile("C:/test.txt", "D:/test111.txt") '兩個參數的文件名部分可以不同set fso = nothing

刪除文件

dim fsoset fso = server.CreateObject("Scripting.FileSystemObject")fso.DeleteFile("C:/test.txt")set fso = nothing

創建文件夾

dim fsoset fso = server.CreateObject("Scripting.FileSystemObject")fso.CreateFolder("C:/test") '目標文件夾的父文件夾必須存在set fso = nothing

判斷文件夾是否存在

dim fsoset fso = server.CreateObject("Scripting.FileSystemObject")if fso.FolderExists("C:/Windows") then  response.Write("目標文件夾存在")else  response.Write("目標文件夾不存在")end ifset fso = nothing

刪除文件夾

dim fsoset fso = server.CreateObject("Scripting.FileSystemObject")fso.DeleteFolder("C:/test") '文件夾不必為空set fso = nothing

這篇文章就介紹到這,更多的大家可以查看VEVB武林網以前發布的關于vbs txt操作的相關文章。


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 中山市| 曲松县| 赫章县| 蕉岭县| 塘沽区| 兴国县| 临海市| 芦溪县| 广宁县| 澎湖县| 双江| 额济纳旗| 梓潼县| 凤山县| 那曲县| 沙雅县| 石楼县| 安泽县| 萨迦县| 苏州市| 大英县| 乌恰县| 永嘉县| 古丈县| 宾川县| 新乐市| 云林县| 宣武区| 家居| 富顺县| 德令哈市| 祥云县| 淄博市| 和平区| 兴仁县| 岳西县| 浦江县| 晴隆县| 广汉市| 云和县| 崇文区|