Batch filename rename depends on its number

April 3, 2010 at 23:27:27
Specs: Windows 7
Hello everyone,
I got a problem about rename a batch of files with numbers. e.g.:

IMG_4567.JPG
IMG_4568.JPG
IMG_4573.JPG ... etc.
(may got some number skipped)

but now I want to rename all depends on its file number.

e.g.:

IMG_4567.JPG --> IMG_3357.JPG
IMG_4568.JPG --> IMG_3358.JPG
IMG_4573.JPG --> IMG_3463.JPG ... etc.

I want to decrease all the file number by 1110

how can I do it?? please help me brother >___<


See More: Batch filename rename depends on its number

Report •

#1
April 4, 2010 at 00:54:50
The 3rd example is a decrease of 1110; the other 2 aren't.


=====================================
Helping others achieve escape felicity

M2


Report •

#2
April 4, 2010 at 04:23:25
sorry
typing mistake
should be like this

e.g.:

IMG_4567.JPG --> IMG_3457.JPG
IMG_4568.JPG --> IMG_3458.JPG
IMG_4573.JPG --> IMG_3463.JPG ... etc.

I want to decrease all the file number by 1110 or any constant number

is it possible? can any brother help me? thx a lot ~


Report •

#3
April 4, 2010 at 20:51:35
NOT tested, hence the "echo" only! test first, then activate if you see what you want to see.
@echo off & setlocal enabledelayedexpansion
for /f "tokens=1,2 delims=_" %%a in ('dir /b *.jpg') do (
set /a xx=%%b-1110
:: remove colon in foll. to activate
:move /y %%a_%%b.jpg %%a_!xx!.jpg
echo heres the rename: %%a_%%b.jpg to %%a_!xx!.jpg
)

Report •

Related Solutions

#4
April 5, 2010 at 04:15:05
Threadstarter, what should happen if the existing target number already exists ?


Report •

#5
April 5, 2010 at 23:52:41
Hi nbrane,
I got a error like this

Missing operator.
The system cannot find the file specified.
heres the rename: IMG_4567.jpg.jpg to IMG_4567.jpg
Missing operator.
The system cannot find the file specified.
heres the rename: IMG_4568.jpg.jpg to IMG_4568.jpg
Missing operator.
The system cannot find the file specified.
heres the rename: IMG_4573.jpg.jpg to IMG_4573.jpg

I am not sure what's worng with the code, can you help me?


Hi tvc,
since the number of file will only got a few hundred, target number already exists will not be happen. thx


Report •

#6
April 6, 2010 at 03:29:07
DLNM, run with ECHO ON, see on which command the message is thrown, examine that command

Report •

#7
April 6, 2010 at 09:27:45
sorry, it was late and i was tired, fix:
for /f ...... do (
set /a xx=%%b-1110
to:
for /f ...... do (
set xx=%%~nb
set /a xx-=1110
::--- and proceed with the rest, see what ya get.

Report •

#8
April 6, 2010 at 19:46:58
thx everybody ~ I can do what I want with the following script.

@echo off & setlocal enabledelayedexpansion
for /f "tokens=1,2 delims=_." %%a in ('dir /b *.jpg') do (
set xx=%%~nb
set /a xx-=1110
move /y %%a_%%b.jpg %%a_!xx!.jpg
echo heres the rename: %%a_%%b.jpg to %%a_!xx!.jpg
)


Report •

Ask Question