假设我有一个文件夹树,例如:
C:\Users\Test\My Documents
C:\Users\Test2
C:\Users\Test3\My Documents
我可以运行什么命令来搜索C:\Users
以检查哪些子文件夹有My Documents
文件夹?
因此对于上述内容,它将返回:
C:\Users\Test\My Documents
C:\Users\Test3\My Documents
但不是
C:\Users\Test2
另外,如果我想编写脚本重命名任何被发现被调用的子文件夹My Documents
并将它们重命名为Documents
,我该如何实现呢?
答案1
DIR /AD /B "My Documents" /S
用于列出文件夹
答案2
这是一个 vbscript,它也会为您重命名文件夹:
Root = INPUTBOX("Please enter the root folder (all subfolders will be renamed)" & vbcrlf & "e.g. C:\TEST")
IF Root="" THEN Canceled
FindStr = INPUTBOX("Please enter the string that you want to find")
IF FindStr = "" THEN Canceled
ReplaceStr = INPUTBOX("Please enter the string that you want to replace it with")
IF ReplaceStr = "" THEN Canceled
SET objFSO= CREATEOBJECT("Scripting.FileSystemObject")
EnumFolders Root
SUB EnumFolders(BYVAL Folder)
SET objFolder = objFSO.GetFolder(Folder)
SET colSubfolders = objFolder.Subfolders
FOR EACH objSubfolder in colSubfolders
NewFolderName = (REPLACE(objSubfolder.name, findstr, replacestr))
IF NewFolderName <> objSubFolder.Name THEN
objSubFolder.Name = NewFolderName
END IF
enumfolders objSubfolder.path
NEXT
END SUB
SUB Canceled
wscript.echo "Script Canceled"
wscript.quit
END SUB
来源:http://www.wisesoft.co.uk/scripts/vbscript_recursive_folder_rename.aspx
PS:我没有测试过。请先使用空目录结构进行测试。