Re: Replacing a string in a filename



Stefan Kanthak wrote:
"Andy Yew" <none@xxxxxxxx> wrote:


billious wrote:

"Andy Yew" <none@xxxxxxxx> wrote in message news:uINToQDrFHA.2072@xxxxxxxxxxxxxxxxxxxxxxx


I need help in writing something that can take the filename as a string
and being able to rename that file into something else. For example,
"A&B.dgn" to "A and B.dgn"

I've gotten some sample batch scripts that does renaming but I guess I
have a hard time understanding them.

What's also the difference between %%i and %i in the scripts that use
FOR command in them?

Thanks.


Second question's easy. Single % where the FOR is executed directly from the command-prompt. Double if used WITHIN a batch file.

No doubt the 'replace "&" with " and " within a filename' problem could be solved using pure-batch, but it's a lot easier using SED (Google is your friend...)


There's no need to bother with SED and ECHO and temporary batch files:

--- .CMD ---
FOR %%! IN (*^&*.dwg) DO CALL :RENAME "%%!"
GOTO :EOF

:RENAME
SET FROM=%1
SET TO=%FROM:&= and %
IF EXIST %TO% GOTO :EOF
RENAME %FROM% %TO%
GOTO :EOF
--- EOF ---

Stefan


Whoa. That's great! Didn't know you could specify patterns to change in the Set command.

Thanks!
.



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!
    ... and I want to rename them to follow a date-roll-shot number: ... goto:EOF ... Then the photo site changed the way they named the individual files. ...
    (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: 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: [PATCH v5 04/16] PCI: prevent duplicate slot names
    ... We now rename these duplicate slots on behalf of the user. ... The hotplug driver creates the slot with its desired name, ... goto error_info; ... struct pci_bus of parent bridge ...
    (Linux-Kernel)