Windows – How to create batch file to rename large number of files in a folder

batch-filecmdrenamewindows

I'd like to rename a large number of files within a folder on a WinXP system, preferably using a batch file.

The files are currently named like this:

Vacation2010 001.jpg
Vacation2010 002.jpg
Vacation2010 003.jpg

And I'd like to change them to:

December 001.jpg
December 002.jpg
December 003.jpg

How can I perform this operation??

Best Answer

@echo off
SETLOCAL ENABLEDELAYEDEXPANSION
SET old=Vacation2010
SET new=December
for /f "tokens=*" %%f in ('dir /b *.jpg') do (
  SET newname=%%f
  SET newname=!newname:%old%=%new%!
  move "%%f" "!newname!"
)

What this does is it loops over all .jpg files in the folder where the batch file is located and replaces the Vacation2010 with December inside the filenames.