[英]How to add diffrent prefix to file names in a folder using Windows command line (reading prefix names from textfile)?
I got a huge list of images in a folder (3000 images). 我在一个文件夹中找到了大量图像(3000张图像)。 Now I want to add a prefix to all these image names.
现在,我想为所有这些图像名称添加一个前缀。 The prefix for each image is different and the prefix is obtained from a text file.
每个图像的前缀是不同的,并且前缀是从文本文件获得的。
My text file looks like this 我的文本文件看起来像这样
mango,A.jpg
apple,B.jpg
orange,c.jpg
and i want to change image names fromA.jpg,B.jpg,C.jpg to: 我想将图像名称从A.jpg,B.jpg,C.jpg更改为:
mango_A.jpg
apple_B.jpg
orange_C.jpg
Could any one tell me how this can be done using a windows batch file? 有人可以告诉我如何使用Windows批处理文件吗?
Easy, try this: 很简单,试试这个:
pushd C:\..[Folder Path]
for /f "tokens=1,2 delims=," %%a in (list.txt) do (
ren "%%~b" "%%~a_%%~b"
)
And you're done! 大功告成!
This is based on Mona's suggestion but is a little more robust, even if you have finished the task. 这是基于蒙娜娜(Mona)的建议,但即使您已完成任务,它也会更加健壮。
The prefix should not contain a comma, else the first comma will be where the prefix is taken up to. 前缀不应包含逗号,否则第一个逗号将是前缀所占的位置。
Place this batch file
and list.txt
in the folder with your files and launch the batch file. this batch file
和list.txt
放在文件所在的文件夹中,然后启动该批处理文件。
As it stands it will echo
each rename command and pause
for a keypress, for you to verify that it is doing what you need to do. 照原样,它将
echo
每个重命名命令并pause
按键,以便您验证它是否在做您需要做的事情。
Remove the echo
and pause
to make it functional. 删除
echo
并pause
以使其起作用。
@echo off
for /f "tokens=1,* delims=," %%a in (list.txt) do (
if exist "%%b" echo ren "%%b" "%%a_%%b"
pause
)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.