使用批处理文件重命名文件夹中的多个图像
我有一个充满图像的文件夹,其格式为 filename.com_XXX_IMG_000.jpg。出现此问题的原因是文件名中包含 .com,它使我用来将其上传到网络空间的软件感到困惑。
我需要创建一个批处理文件,获取文件夹中的所有图像,并从 filename.com_XXX_IMG_000.jpg => 重命名所有图像。文件名_XXX_IMG_000.jpg。
任何帮助将非常感激,提前致谢。
I have a folder full of images which have a format filename.com_XXX_IMG_000.jpg. The issue comes because the file name has a .com in it, it confuses the the software that I am using to upload it to a webspace.
I need to create a batch file that gets all the images in a folder and renames all of them from filename.com_XXX_IMG_000.jpg => filename_XXX_IMG_000.jpg.
Any help would be greatful, thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
由于您想在批处理文件中执行此操作:
一些注意事项
for
循环变量是单个字母,如下所示:%f
%
必须转义,因此%f
变为%%f
delims=.
在.
处分割文件名。 code>,在你的情况下分为三个部分tokens=1,2,3
返回三个包含各个名称部分的变量(%f
、%g
和%h)
enabledelayedexpansion
打开动态变量处理,%foo:~0,3%
返回%foo 的前三个字符%。
!
而不是%
来访问更改其值的变量,>
必须转义或echo
不会打印它,因此^>
Since you want to do it in a batch file:
A few notes
for
loop variables are single letter, like this:%f
%
must be escaped, so%f
becomes%%f
delims=.
splits the filenames at the.
, in your case into three partstokens=1,2,3
returns three variables containing the individual name parts (%f
,%g
and%h
)enabledelayedexpansion
switches on dynamic variable handling%foo:~0,3%
returns the first three characters of%foo%
.!
instead of%
>
must be escaped orecho
won't print it, hence^>
阅读
HELP FOR
并尝试以下操作...您需要启用延迟扩展,因为您需要在 for 循环内扩展变量。
循环遍历当前目录中的所有 jpg 文件,并使用
~n
语法为每个文件提取其文件名,然后删除所有出现的.com
通过用空字符串替换它们。 仔细测试后阅读HELP SET
,去掉
echo
命令read
HELP FOR
and try the following....you need to enable delayed expansion because you need to expand a variable inside the for loop.
the loops iterates over all the jpg files in the current directory and for each file it extracts its filename using the
~n
syntax, and then it removes all the occurences of.com
by replacing them with an empty string. ReadHELP SET
after careful testing, remove the
echo
command