Re: Command Line Question about Renaming Files

From: Mark & Mary Ann Weiss (mweissX294_at_earthlink.net)
Date: 03/25/04


Date: Thu, 25 Mar 2004 01:43:20 GMT


> > :Strip
> > set name=%*
> > set NewName=%name:~3%
> > echo ren "%Name%" "%NewName%" >> %temp%\newname.bat
> >
> >
> > I have a vague idea of what is intended and that the key here is the
"~3%"
> > portion, but I tried the set command one line at a time to see if the
> > environment would accept it and all that became persistent was "set
> > name=%*". The line after it might be invalid, as setting that does not
> > include it in the environment.
> >
> > What exactly does the "~3%" statement do? Does it mean "delete first
three
> > characters? What does "~" mean in this context?
> >
> >
> > --
> > Take care,
> >
> > Mark & Mary Ann Weiss
> >
> > VIDEO PRODUCTION . FILM SCANNING . AUDIO RESTORATION
> > Hear my Kurzweil Creations at: http://www.dv-clips.com/theater.htm
> > Business sites at:
> > www.dv-clips.com
> > www.mwcomms.com
> > www.adventuresinanimemusic.com
> > -
>
> I am puzzled as to what's going on on your machine. Are
> you running Win2000?
>
> I have modified the batch file to add some diagnostics.
> Run it again until it throws up the first error, then post
> a screen dump.
>
> @echo on
> if exist "%temp%\NewName.bat" del "%temp%\NewName.bat"
>
> for %%* in (*.*) do (call :Strip %%* & pause)
> echo Examine "%temp%\NewName.bat" to see what will happen,
> echo then execute "%temp%\NewName.bat."
>
> rem call "%temp%\NewName.bat"
> rem del "%temp%\NewName.bat"
> goto :eof
>
> :Strip
> set name=%*
> set NewName=%name:~3%
> echo ren "%Name%" "%NewName%" >> "%temp%\newname.bat"
>

Win2K SP4 here, to be exact.
I found the problem...
It had to do with how I was sending the commands to the command processor.
I assumed that I could paste it into the cmd window like I do with single
line commands, but apparently the bat file has to exist on the drive for
this bat file to work.
So I pasted to a text file, renamed it 'ren.bat' and copied it to the folder
where I wanted to strip out the first three numerical characters. It works.
It does rename itself in the process and generates an error, but all the
files I wanted renamed are renamed appropriately.

I don't fully understand how your batch file works, but thanks for providing
a solution to my batch renaming challenge.

--
Take care,
Mark & Mary Ann Weiss
VIDEO PRODUCTION . FILM SCANNING . AUDIO RESTORATION
Hear my Kurzweil Creations at: http://www.dv-clips.com/theater.htm
Business sites at:
www.dv-clips.com
www.mwcomms.com
www.adventuresinanimemusic.com
-


Relevant Pages

  • Re: VFP 6 - problem with RUN command
    ... I think you simply need to de-bug your .bat file. ... Toos VFP to the side for ... The PAUSE command, however, functions beautifully now. ... and a CALL command to another batch file doesn't work, ...
    (microsoft.public.fox.programmer.exchange)
  • Re: VFP 6 - problem with RUN command
    ... Does your .BAT file run OK if you run it from Windows Explorer? ... and a CALL command to another batch file doesn't work, ... If I place a SUSPEND command immediately before the RUN command, ...
    (microsoft.public.fox.programmer.exchange)
  • Re: Shell & VBA
    ... run the command. ... > SHELL command. ... > When manually I execute this batch file, ...
    (microsoft.public.excel.programming)
  • Re: Batch Rename
    ... If a wild card can't be used, I will just get it setup manually once, open the file in Excel and use the replace command. ... If you don't want to write a batch file yourself, one of my favorite freeware applications, Irfanview, includes a batch rename facility. ... To the moon and back with 64 Kbits of RAM and 512 Kbits of ROM. ...
    (microsoft.public.windowsxp.general)
  • Re: Batch Rename
    ... it before you can run the batch file. ... word "echo" in the last line in order to activate it. ... I did some playing around with the "RENAME" command, ...
    (microsoft.public.windowsxp.general)