1个回答
展开全部
看下代码符合要求不
Set f= CreateObject("Scripting.FileSystemObject")
Set f1 = f.OpenTextFile("Text.txt")
str=f1.ReadAll
f1.close
str = Replace(str, "蠢驴", "笨猪")
set f2=f.createtextfile("~text.txt")
f2.write(str)
f2.close
f.MoveFile "~text.txt" , "C:\text.abc"
VBS 文件操作
创建文本文件
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")
文本操作
读取全部内容
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)
改格式用下面的
重命名文件(其实也是移动文件)
Set objFSO = CreateObject("Scripting.FileSystemObject")
objFSO.MoveFile "C:\1.txt" , "C:\1.bat"
移动文件
Set objFSO = CreateObject("Scripting.FileSystemObject")
objFSO.MoveFile "c:\1.txt" , "d:\1txt"
Set f= CreateObject("Scripting.FileSystemObject")
Set f1 = f.OpenTextFile("Text.txt")
str=f1.ReadAll
f1.close
str = Replace(str, "蠢驴", "笨猪")
set f2=f.createtextfile("~text.txt")
f2.write(str)
f2.close
f.MoveFile "~text.txt" , "C:\text.abc"
VBS 文件操作
创建文本文件
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")
文本操作
读取全部内容
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)
改格式用下面的
重命名文件(其实也是移动文件)
Set objFSO = CreateObject("Scripting.FileSystemObject")
objFSO.MoveFile "C:\1.txt" , "C:\1.bat"
移动文件
Set objFSO = CreateObject("Scripting.FileSystemObject")
objFSO.MoveFile "c:\1.txt" , "d:\1txt"
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询