简体   繁体   English

如何使用Windows命令行在文件夹中的文件名中添加差异前缀(从文本文件中读取前缀名称)?

[英]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 filelist.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. 删除echopause以使其起作用。

@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.

相关问题 如何重命名文件夹下的所有文件名以在Windows中添加修改日期作为前缀 - How to rename all file names under a folder to add modified date as prefix in Windows 在文件名中添加序列前缀 - Add sequence prefix to file names Windows批处理为文件名添加前缀,为什么添加了两次? - Windows batch to add prefix to file names, why added twice? 是否可以自动将前缀附加到从文件夹名称中提取的文件名? (视窗) - Is it possible to append prefix to files names taken from folder name, automatically? (Windows) 如何使用Windows命令行获取已删除的临时文件名列表和只读文件名列表? - How to get the deleted temp file names list and read only file names list using windows command line? 如何在Windows命令行中对文件名进行数字排序? - How to sort file names numerically in windows command line? 重命名文件夹中的多个文件,添加前缀 (Windows) - Rename multiple files in a folder, add a prefix (Windows) 如何使用批处理文件向当前文件夹和子文件夹中的所有文件添加前缀 - How to Add prefix to all file in current folder and subfolder using batch file 如何用命令行替换文本文件中的每个前缀? - How to replace every prefix in a text file with command line? 如何使用命令行从网络驱动器中提取文件名 - How to use command line to pull file names from a network drive
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM