这篇文章将为大家详细讲解有关如何在vbs中操作txt文本文件,文章内容质量较高,因此小编分享给大家做个参考,希望大家阅读完这篇文章后对相关知识有一定的了解。创建文件dim fso, fset fso
这篇文章将为大家详细讲解有关如何在vbs中操作txt文本文件,文章内容质量较高,因此小编分享给大家做个参考,希望大家阅读完这篇文章后对相关知识有一定的了解。
创建文件
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
关于如何在vbs中操作txt文本文件就分享到这里了,希望以上内容可以对大家有一定的帮助,可以学到更多知识。如果觉得文章不错,可以把它分享出去让更多的人看到。
--结束END--
本文标题: 如何在vbs中操作txt文本文件
本文链接: https://www.lsjlt.com/news/253079.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
下载Word文档到电脑,方便收藏和打印~
2024-04-30
2024-04-30
2024-04-29
2024-04-29
2024-04-29
2024-04-29
2024-04-29
2024-04-29
2024-04-29
2024-04-29
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0