Re: The killer space!



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 2006-08-16-03-%newname%%~x1
goto :EOF

.



Relevant Pages

  • Re: The killer space!
    ... and I want to rename them to follow a date-roll-shot number: ... @echo off ... goto:EOF ...
    (microsoft.public.scripting.vbscript)
  • Re: The killer space!
    ... goto:EOF ... rename %1 %rolldate%%newname%%~x1 ... Todd, I believe you were a bit hasty in your response. ...
    (microsoft.public.scripting.vbscript)
  • Re: The killer space!
    ... goto:EOF ... rename %1 %rolldate%%newname%%~x1 ... the rename subroutine will already be parsed at the space before it ...
    (microsoft.public.scripting.vbscript)
  • Re: Replacing a string in a filename
    ... and being able to rename that file into something else. ... IF EXIST %TO% GOTO:EOF ... Didn't know you could specify patterns to change in the Set command. ...
    (microsoft.public.win2000.cmdprompt.admin)
  • The killer space!
    ... A friend created a .bat file for me so I could easily rename files I ... goto:EOF ... Then the photo site changed the way they named the individual files. ...
    (microsoft.public.scripting.vbscript)