使用这样的脚本,通过你的文件夹中的所有文件首先迭代:
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
应该正常工作(但我没有测试)。我希望我引发了你的好奇心,并且你会研究这个代码的工作机制。这就是为什么我加入了可以找到文档的链接。
好工作:)谢谢:) 其实我看着代码的机制,并试图使其更有活力。当我尝试使用二维数组变量来做到这一点时,我失败了。不知道为什么。 '昏暗SearchFileName(4,2) SearchFileName(0,0)= “允许KilobyteData”' – 2013-02-26 21:22:38
问题解决:) – 2013-02-26 21:30:51