I have a directory of product images that I'd like to rename to the products's UPC. I have the file name mapping in a spreadsheet, so I can export it to CSV or tab delimited.

Given filenames.txt:

CurrentName     NewName
DSCN4033.png    750732000259.png
DSCN4023.png    750732000013.png
DSCN4024.png    750732000020.png
DSCN4022.png    750732000099.png

DSCN4033.png would become 750732000259.png

If I were doing this with Bash, the command would be

while read old new; do mv "$old" "$new"; done < filenames.txt

This is for a project at work that must be done with a Windows batch file so that my successors don't have to mess with Cygwin.


Provided there are no spaces in your current names, then the following should work from the command line:

for /f "skip=1 tokens=1*" %A in (filenames.txt) do ren "%A" "%B"

The percents must be doubled if put in a batch file:

@for /f "skip=1 tokens=1*" %%A in (filenames.txt) do ren "%%A" "%%B"

FOR is the most complicated internal command available to CMD.EXE. Use help for or for /? from the command line to access the documentation.

  • 1
    Whoa. I never would have thought to look inside FOR for this kind of functionality. – picobit May 23 '16 at 15:27

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.