Batch file 如何使批处理文件编辑文本文件
我知道密码了Batch file 如何使批处理文件编辑文本文件,batch-file,scripting,dos,Batch File,Scripting,Dos,我知道密码了 Set objFS = CreateObject("Scripting.FileSystemObject") strFile = "C:\test\file.txt" Set objFile = objFS.OpenTextFile(strFile) Do Until objFile.AtEndOfStream strLine = objFile.ReadLine If InStr(strLine,"ex3")> 0 Then strLine
Set objFS = CreateObject("Scripting.FileSystemObject")
strFile = "C:\test\file.txt"
Set objFile = objFS.OpenTextFile(strFile)
Do Until objFile.AtEndOfStream
strLine = objFile.ReadLine
If InStr(strLine,"ex3")> 0 Then
strLine = Replace(strLine,"ex3","ex5")
End If
WScript.Echo strLine
Loop
strLine替换部分我可以自己修复以用于我自己的目的,但是我如何做这样的事情,使其不需要文件名,它只编辑文档中的所有文本文件?您可以这样做
strFolder = "c:\myfolder"
Set objFolder = objFS.GetFolder(strFolder)
For Each strFile In objFolder.Files
strFileName =strFile.Name
strFilePath = strFile.Path
strFileExt = objFS.GetExtensionName(strFile)
If strFileExt = "txt" Then
Set objFile = objFS.OpenTextFile(strFile)
' your current code here..
objFile.Close()
End If
Next
您可以将文件名作为参数传递给脚本。但是你说的“编辑文档中的所有文本文件”是什么意思?在文件夹中,我在快速打字。很抱歉,我会删除文件夹中所有文本文件,这些文件将位于“strFile”行中。