用于重命名文件夹参数中的文件的批处理脚本
我找不到任何参考资料来解释如何循环遍历作为参数传递的文件夹并重命名每个文件。我见过的所有示例都假设脚本在文件将被重命名的文件夹中运行,或者在循环中对文件夹路径进行硬编码。我该怎么做?这是我正在尝试做的事情的一个例子:
for /f %%a in (%1) do call :RenameFiles
:RenameFiles
Rename %%a "new filename"
Goto :EOF
I can't find any references explaining how to loop through a folder passed as an argument and rename each file. All examples I've seen assume the script is running in the folder where files will be renamed or hardcode the folder path in the loop. How can I do this? Here is an example of what I'm trying to do:
for /f %%a in (%1) do call :RenameFiles
:RenameFiles
Rename %%a "new filename"
Goto :EOF
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
以下代码将前缀“renamed-”添加到指定为命令行参数的目录中的每个文件:
编辑 无限循环问题的最简单解决方案是分两个阶段工作:
-
The following adds prefix "renamed-" to every file in the directory specified as a command line argument:
EDIT The simplest solution to the problem of the infinite loop is to work in two stages:
-