Renaming multiple files

P

PSRumbagh

I have a file folder that contains hundreds of .jpg files named such as
im00002.jpg, im00018.jpg, im044.jpg, im00137.jpg, etc. Using some sort of
batch process, I would like to rename them without all the leading zeros,
i.e. im2.jpg, im18.jpg, im44.jpg, im137.jpg. How do I do this?
 
P

PcCare

copy this code into a command file, make sure you have a backup before running

for /r %%i in (*.jpg) do call :renameit %%~nxi

goto :EOF

:renameit
set filename=%1
echo Renaming %filename% to %filename:0=%
rename %filename% %filename:0=%
goto :EOF
 
P

PSRumbagh

Thanks. The batch file works great. Could you explain to a neophyte what
each line does? Can you refer me to a good tutorial on writting batch files?
 
R

rod

FYI
If you have ACDSee image program,
this will work for you.
It will accept wildcards as well ## for renaming
to whatever taste, example "holidays in Spain ###" will
rename :Holidays in Spain 0 to 999 or you can nominate from which number
to begin.
I am not sure but kinda remember seeing an early 1Mb example
of ACDSee legally free somewhere, or maybe that was Snagit.
HTH
 
T

Timothy Daniels

PSRumbagh said:
I have a file folder that contains hundreds of .jpg files named such as
im00002.jpg, im00018.jpg, im044.jpg, im00137.jpg, etc. Using some sort of
batch process, I would like to rename them without all the leading zeros,
i.e. im2.jpg, im18.jpg, im44.jpg, im137.jpg. How do I do this?

January's PCWorld (p. 100) likes this freeware to rename files in bulk:
Lupas Rename 2000 -
http://www.pcworld.com/downloads/file/fid,52120-page,1-c,filemanagement/description.html

*TimDaniels*
 
P

Pegasus \(MVP\)

PcCare used advanced batch file techniques in his reply.
Here is a brief explanation of each line:

for /r %%i in (*.jpg) do call :renameit %%~nxi

This command enumerates all .jpg files in the current
folder and invokes the "rename" subroutine, passing
as a parameter just the file name (the "~n" component)
plus the extension (the "~i" component) but not the
path name. You see find a full explanation when you
type for /? at the Command Prompt.

goto :EOF

This command causes the batch file to terminate after
it has dealt with all .jpg files.

:renameit

This is the starting label for the subroutine.

set filename=%1

This command sets the variable "filename" to the value
that gets passed from the main program. It should actually
read as follows to deal with file names that have embedded
spaces:

set filename=%*

echo Renaming %filename% to %filename:0=%

This line gives you on-screen feedback.

rename %filename% %filename:0=%

This line performs the renaming. It translates every
"0" character to a blank. The command is explained
when you type set /? at the Command Prompt.
In its current form it actually has a flaw: It will remove
ALL "0"s, regardless of where they occure. Thus it
will do both of the following:

000137.jpg -> 137.jpg
000130.jpg -> 13.jpg

goto :EOF

This command is superfluous. It can be omitted.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top