Solved rename files to series numbers

March 28, 2012 at 07:47:01
Specs: Windows 7
hello everybody i have folder contains photos named like :

samy-pic.jpg
jon-pic.jpg
nice-pic.jpg
stares-photo.jpg
sky-photo.jpg
and so on


i need a batch that look for files contains "pic" word and rename the file to series number 4 digits start with 0001 so :

samy-pic.jpg >>>> 0001.jpg
jon-pic.jpg >>>>>>0002.jpg
nice-pic.jpg >>>>>0003.jpg
stares-photo.jpg >>no change
sky-photo.jpg>>>>no change

note : the folder contains more than 500 files with different names

is that possible ????? i hope so


See More: rename files to series numbers

Report •


✔ Best Answer
March 28, 2012 at 09:55:45
set cnt=0
for %%a in (*pic.jpg) do call :renfile "%%a"
goto :eof

:renfile
set /a cnt += 1
set padCnt=0000%cnt%
ren %1 %padCnt:~-4%%~x1

How To Ask Questions The Smart Way



#1
March 28, 2012 at 08:34:09
Will they always end with "pic.jpg"?

How To Ask Questions The Smart Way


Report •

#2
March 28, 2012 at 08:47:09
rem compleatly untested perhaps

set /a named == 0
FOR /R C:\pictures\ %%G IN (*pic.jpg) DO (
call :subroutine
rename %%G %named%.jpg

:subroutine
:check
set /a named == (named+1)
if exist %named%.jpg goto check
GOTO:eof

mike


Report •

#3
March 28, 2012 at 08:56:41
yes they will always end with "pic.jpg"

Report •

Related Solutions

#4
March 28, 2012 at 09:09:49
i have tested your code mikelinus it changes only one picture to no name .jpg
i think that happens coz the loop in that code return to the same file and not to the next one i hope to make changes on it and thanks for trying

Report •

#5
March 28, 2012 at 09:55:45
✔ Best Answer
set cnt=0
for %%a in (*pic.jpg) do call :renfile "%%a"
goto :eof

:renfile
set /a cnt += 1
set padCnt=0000%cnt%
ren %1 %padCnt:~-4%%~x1

How To Ask Questions The Smart Way


Report •

#6
March 28, 2012 at 10:17:49
thank you very much razor it work like a charm .. you are a great man .. i dont know what to say ... thanksssssssssssssssssssssssssssssssssssssssss

Report •


Ask Question