重命名多个文件夹.bat文件 [英] .bat file for renaming multiple folders
问题描述
我试图写一个批处理脚本来重命名多个文件夹。
我愿做这样的事情如下:
通过在文件夹名称的结尾
I am trying to write a batch script to rename multiple folders. I would like to do something like below : Rename all folders under the "Workspace" folder by appending my name in the end of the folder names
例如:结果
重命名
工作区/ RiskFolder,工作区/ PNLFolder的到工作区/ RiskFolder_myname,工作区/ PNLFolder_myname
Example:
Rename
Workspace/RiskFolder, Workspace/PNLFolder to Workspace/RiskFolder_myname, Workspace/PNLFolder_myname
这可能吗?
非常感谢事先!
推荐答案
您可以通过每个目录使用循环和像这样其重命名为:
You could use for to loop through each directory and rename it like so:
for /D %%f in (C:\path\to\Workspace\*) do rename "%%f" "%%~nxf_myname"
我测试了在Windows 7上,但它应该工作至少可以追溯到与Windows XP。
I tested this on Windows 7, but it should work at least as far back as with Windows XP.
什么,这是否是:在路径(括号内)每个目录,指定目录名称变量 %%˚F
,然后重命名目录 %%˚F
来你想要的格式名称(您的姓名附后)。 %%˚F
保存的完整路径,这是很好的第一个参数改名
命令,但第二的说法,我们只需要在文件名+扩展,因此〜NX修改prepended我们的变量名。
What that does is this: for each directory in the path (within parenthesis), assign the directory name to the variable %%f
, then rename the directory %%f
to the name in the format you want (with your name attached). %%f
holds the full pathname, which is fine for the first argument to the rename
command, but for the second argument, we only want the filename+extension, thus the ~nx modifier prepended to our variable name.
顺便说一句,使用命令行对这个为
循环时(而不是一个批处理文件的一部分),你只需要使用一个%,而不是%%为您的变量名。例如。 中......%F
,而不是上面。
By the way, when using this for
loop on the command line (rather than part of a batch file) you only want to use one % instead of %% for your variable name. E.g. for %f in...
instead of above.
请参阅Microsoft提供的以下参考资料了解更多详情:
See the following references from Microsoft for more details:
- http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/batch.mspx?mfr=true
- http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/for.mspx?mfr=true
这篇关于重命名多个文件夹.bat文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!