Re: The killer space!
- From: Tom Lavedas <tglbatch@xxxxxxx>
- Date: Sat, 16 Feb 2008 07:41:59 -0800 (PST)
On Feb 16, 2:38 am, "Todd Vargo" <tlva...@xxxxxxxxxxxxxx> wrote:
sand wrote:
A friend created a .bat file for me so I could easily rename files I
download from a photo site. The site names each file: Picture_1.jpg
and I want to rename them to follow a date-roll-shot number:
2008-02-15-01-01.
So here's the script:
------
::BatchRename.cmd
@echo off
for /f %%i in ('dir /b') do call :rename %%i
goto :EOF
:rename
set Oldname=%1
set NewName=%oldname:Picture_=2006-08-16-03-%
rename %oldName% %newname%
goto :EOF
------
Then the photo site changed the way they named the individual files.
So instead of "Picture_1.jpg" there is now a space instead of the
underline so it reads "Picture 1.jpg".
And the script doesn't work anymore.
Could some one help me update the .bat file so it can handle the empty
space?
::BatchRename.cmd
@echo off
for /f %%i in ('dir /b') do call :rename "%%i"
goto :EOF
:rename
set NewName=%~n1
set NewName=0%NewName:Picture =%
set NewName=%NewName:~-2%
rename %1 %rolldate%%newname%%~x1
goto :EOF
Todd, I believe you were a bit hasty in your response. The double
quotes are only part of the answer. I think you were misled by the
unnecessary use of the 'dir /b' and the /F switch. The argument to
the rename subroutine will already be parsed at the space before it
arrives as a parameter to the subroutine call.
Here is my put (with a prompt for the variable part [rolldate]) ...
::BatchRename.cmd
@echo off
if not defined rolldate set /p rolldate=Enter roll date:
if not defined rolldate %0
for %%i in (*.jpg) do call :rename "%%i"
goto :EOF
:rename
set OldName=%~1
echo rename %1 "%rolldate%-%OldName:~8%"
goto :EOF
The roll date is to be supplied without the final hyphen.
This approach will work with either input naming convention.
Tom Lavedas
===========
.
- Follow-Ups:
- Re: The killer space!
- From: Todd Vargo
- Re: The killer space!
- References:
- The killer space!
- From: sand
- Re: The killer space!
- From: Todd Vargo
- The killer space!
- Prev by Date: script doesn't run under xp
- Next by Date: Re: joining excel-sheets to one
- Previous by thread: Re: The killer space!
- Next by thread: Re: The killer space!
- Index(es):