有人可以帮忙解释我如何编写一些搜索具有特定字符串的文件的vbs脚本并重命名它们吗?
例如,假设我有一个文件夹c:\ test
我想在c:\ test中搜索带有单词John的每个文件,并替换为Dave这个词......
e.g。 内容如下:
john_list.txt auto.john.doc
脚本之后:
dave_list.txt auto.dave.doc
你能帮忙吗?
谢谢!
解决方案:
Dim sName
Dim fso
Dim fol
' create the filesystem object
Set fso = WScript.CreateObject("Scripting.FileSystemObject")
' get current folder
Set fol = fso.GetFolder("c:\TEST")
' go thru each files in the folder
For Each fil In fol.Files
' check if the file name contains underscore
If InStr(1, fil.Name, "john") <> 0 Then
' replace underscore with space
sName = Replace(fil.Name, "john", "dave")
' rename the file
fil.Name = sName
End If
Next
' echo the job is completed
WScript.Echo "Completed!"