0

I got a huge list of images in a folder (3000 images). 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:

mango_A.jpg
apple_B.jpg
orange_C.jpg

Could any one tell me how this can be done using a windows batch file?

user1788736
  • 2,727
  • 20
  • 66
  • 110
  • 2
    Look at [FOR /F](http://stackoverflow.com/a/18177593/463115) and [arrays](http://stackoverflow.com/a/10196352/463115) – jeb Nov 18 '13 at 07:14

2 Answers2

1

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!

Monacraft
  • 6,510
  • 2
  • 17
  • 29
  • Thanks for replies. Monacraft can you tell me how run the above ? furthermore do i need to change this part :ren "%%~b" "%%~a_%%~b" ? or only the texfile name ? can this method work for like 2000 image files without freezing or crushing ? – user1788736 Nov 18 '13 at 07:38
  • look at my edit, and rename the text file list.txt. Also, copy and paste this into a batch file by: opening notepad, pasting this into it, saving as * all file types * and replacing .txt with .bat. – Monacraft Nov 18 '13 at 07:50
0

This is based on Mona's suggestion but is a little more robust, even if you have finished the task.

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.

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.

Remove the echo and pause to make it functional.

@echo off
for /f "tokens=1,* delims=," %%a in (list.txt) do (
   if exist "%%b" echo ren "%%b" "%%a_%%b"
   pause
)
foxidrive
  • 40,353
  • 10
  • 53
  • 68