Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I create batch file to rename large number of files in a folder?

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??

like image 324
user459962 Avatar asked Sep 27 '10 21:09

user459962


1 Answers

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

like image 194
RoXX Avatar answered Sep 19 '22 07:09

RoXX