1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Regex Rename

Discussion in 'Support' started by samintz, Nov 10, 2010.

  1. samintz

    samintz Scott Mintz

    Joined:
    May 20, 2008
    Messages:
    1,177
    Likes Received:
    11
    I have a handful of files that were copied from a "boilerplate" and I want
    to rename the files replacing the boilerplate name with my specific
    project name.

    I want to do something like this:
    ren ::NewApp(.*)+ MyProject\1

    Where everything after "NewApp" is kept but the "NewApp" text is replaced
    with "MyProject". I wanted to use \1 as the first group discovered in the
    regex.

    NewAppClass.cpp ==> MyProjectClass.cpp
    NewAppClass.hpp ==> MyProjectClass.hpp
    NewAppInst.cpp ==> MyProjectInst.cpp
    NewAppInst.hpp ==> MyProjectInst.hpp
    NewAppObj.cpp ==> MyProjectObj.cpp
    NewAppObj.hpp ==> MyProjectObj.hpp

    While I realize I can do this using delayed expansion:
    ren *.[ch]pp "%%@replace[NewApp,MyProject,*]"

    I want to know if it's possible using regex.
    -Scott
     
  2. rconn

    rconn Administrator
    Staff Member

    Joined:
    May 14, 2008
    Messages:
    9,729
    Likes Received:
    80
    TCC does not support regular expressions in the target names, only in the source names. But I believe one of Vince's plugins will do this.
     
  3. vefatica

    Joined:
    May 20, 2008
    Messages:
    7,784
    Likes Received:
    29
    On Sat, 13 Nov 2010 16:12:11 -0500, rconn <> wrote:

    |---Quote (Originally by samintz)---
    |I have a handful of files that were copied from a "boilerplate" and I want to rename the files replacing the boilerplate name with my specific project name.
    |---End Quote---
    |
    |TCC does not support regular expressions in the target names, only in the source names. But I believe one of Vince's plugins will do this.

    4UTILS has @XREPLACE[] which allows regex back-references. But I doubt you
    could use it in a REN command. Rather you'd have to use a loop ...

    FOR %file IN (file_spec) REN %file %@XREPLACE[regex,replacement,%file]

    (or DO ...)

    I'd do a lot of testing before trying it "live".
     

Share This Page