重命名文件的脚本
我在几个不同的文件夹中有大约2200个不同的文件,并且我需要重命名其中大约1/3的文件,这些文件位于它们自己的子文件夹中.那700个文件也位于各个文件夹中.
I have about 2200 different files in a few different folders, and I need to rename about about 1/3 of them which are in their own subfolder. Those 700 are also in various folders as well.
例如,可能有 最上面的文件夹是Employees,里面有几个文件,然后文件夹2002有几个,2003文件夹有更多,2004等.
For example, there might be The top-most folder is Employees, which has a few files in it, then the folder 2002 has a few, 2003 has more files, 2004 etc.
我只需要在每个文件的现有名称前附加协议"一词.因此,与其说是"Joe Schmoe.doc",不如说是协议Joe Schmoe.doc".
I just need to attach the word "Agreement" before the existing name of each file. So instead of it just being "Joe Schmoe.doc" It would be "Agreement Joe Schmoe.doc" instead.
我尝试使用谷歌搜索此类脚本,并且可以找到与所需脚本类似的内容,但是对我来说,它们看起来都是完全陌生的,所以我不知道如何修改脚本以适合自己的需求.
I've tried googling such scripts, and I can find stuff similar to what I want but it all looks completely foreign to me so I can't understand how I'd modify it to suit my needs.
哦,这是针对Windows Server '03.
Oh, and this is for windows server '03.
我需要大约2分钟的时间来为* NIX系统编写这样的脚本(可能更少),但是对于Windows来说却是一首长歌...))
I need about 2 minutes to write such script for *NIX systems (may be less), but for Windows it is a long song ... ))
我已经为WSH编写了简单的VBS脚本,尝试一下(保存到{script-name} .vbs,更改Path值(在脚本的第一行)并执行).我建议第一次对少量数据进行脚本测试,以确保脚本能否正常工作.
I've write simple VBS script for WSH, try it (save to {script-name}.vbs, change Path value (on the first line of the script) and execute). I recommend to test script on small amount of data for the first time just to be sure if it works correctly.
Path = "C:\Users\rootDirectory"
Set FSO = CreateObject("Scripting.FileSystemObject")
Sub visitFolder(folderVar)
For Each fileToRename In folderVar.Files
fileToRename.Name = "Agreement " & fileToRename.Name
Next
For Each folderToVisit In folderVar.SubFolders
visitFolder(folderToVisit)
Next
End Sub
If FSO.FolderExists(Path) Then
visitFolder(FSO.getFolder(Path))
End If