Re: Renaming multiple files
- From: "Pegasus \(MVP\)" <I.can@xxxxxxxxxx>
- Date: Thu, 27 Dec 2007 08:21:51 +0100
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.
for /r %%i in (*.jpg) do call :renameit %%~nxi"PSRumbagh" <PSRumbagh@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
goto :EOF
:renameit
set filename=%1
echo Renaming %filename% to %filename:0=%
rename %filename% %filename:0=%
goto :EOF
news:85147906-3842-40F6-AD21-AB8A6414DF0A@xxxxxxxxxxxxxxxx
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?
"PcCare" wrote:
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
"PSRumbagh" wrote:
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?
.
- References:
- RE: Renaming multiple files
- From: PcCare
- RE: Renaming multiple files
- Prev by Date: Re: delete links to obsolete network resources
- Next by Date: Re: I can't access "Phone and modem option" in Control panel
- Previous by thread: RE: Renaming multiple files
- Next by thread: Re: Renaming multiple files
- Index(es):
Relevant Pages
|
Loading