首先使用如下脚本遍历文件夹中的所有文件:
Dim fso, folder, file
Dim folderName, searchFileName, renameFileTo
' Parameters
folderName = "D:\reports\"
searchFileName = "AMR KilobyteData"
renameFileTo = "AMR KilobyteData.xls"
' Create filesystem object and the folder object
' how the FSO works: http://msdn.microsoft.com/en-us/library/2z9ffy99(v=vs.84).aspx
Set fso = CreateObject("Scripting.FileSystemObject")
Set folder = fso.GetFolder(folderName)
' Loop over all files in the folder until the searchFileName is found
For each file In folder.Files
' See if the file starts with the name we search
' how instr works: http://www.w3schools.com/vbscript/func_instr.asp
If instr(file.name, searchFileName) = 1 Then
file.name = renameFileTo
' Exit the loop, we only want to rename one file
Exit For
End If
Next
它应该可以正常运行(但我没有测试它)。我希望我引发了您的好奇心,您将研究此代码的工作机制。这就是为什么我把可以找到文档的链接放在里面。