Rename multiple files

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
halleluuja
Posts: 1
Joined: 08 Sep 2008 05:45

Rename multiple files

#1 Post by halleluuja » 08 Sep 2008 10:49

Hello,

I would need some help with writing the .bat file that renames all files with same extension (let's say .jpg) in one folder as numeric row.

The original files are:
somefile.jpg
anotherfile.jpg
onemorefile.jpg
. . . . .
(and so on)

And the result supposed to be:
1.jpg
2.jpg
3.jpg
. . .
(etc)

Any ideas?

Thank you

greenfinch
Posts: 36
Joined: 17 Jul 2008 07:37

#2 Post by greenfinch » 08 Sep 2008 18:00

Code: Select all

SETLOCAL

set filecount=1
for /f %%a in ('dir /on /b *.jpg') do (call :rename %%a)
GOTO :EOF


:rename
ren %1 %filecount%.jpg
set /a filecount+=1
GOTO:EOF


This will sort by filename (dir /on) - run dir /? for other options

k3lvinmitnick.co.cc
Posts: 6
Joined: 17 Jun 2009 20:17
Location: http://vietdzung.net
Contact:

#3 Post by k3lvinmitnick.co.cc » 17 Jun 2009 22:22

Nice topic,
Tks,

Post Reply