Solved How to rename my picture file?

April 17, 2012 at 08:55:44
Specs: Windows 7
I have many picture with name:
more than 001.jpg
more than 002.jpg
.
.
more than 354.jpg

i need to rename it to just with its number so its called:
001.jpg
002.jpg
.
.
354.jpg
how can i fix it with batch file
i'm very appreciate your help, thank you....


See More: How to rename my picture file?

Report •


#1
April 17, 2012 at 09:13:11
✔ Best Answer
@echo off
for /f "tokens=*" %%z in ('dir /b *.jpg') do (
	for /f "tokens=3 delims= " %%i in ("%%z") do (
		ren "%%z" "%%i"
	)
)

Tony


Report •

#2
April 17, 2012 at 09:27:20
Great, its work, its very useful, thank you,
can you explain it?

Report •

#3
April 17, 2012 at 09:37:54
It gets a list of filenames matching the filespec *.jpg (the asterisk is a wildcard for any number of characters), then for each of those files matching the filespec (the filename gets set as the variable %%z), tokenize the filename, and use the third token using a space as a delimiter, in this case the third token is set to %%i, which expands to 001.jpg, 002.jpg...354.jpg.

On the first loop through, %%z is set to 'more than 001.jpg' and %%i is set to '001.jpg', at which point the files are renamed using the values stored in those variables.

Tony


Report •

Related Solutions

#4
April 17, 2012 at 09:47:12
I got it.. Thanks again...

Report •


Ask Question