Regex Rename

samintz

Scott Mintz
May 20, 2008
1,270
11
Solon, OH, USA
#1
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
 

rconn

Administrator
Staff member
May 14, 2008
10,551
97
#2
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.
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
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".