Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

Regex Rename

samintz

Scott Mintz
May
1,582
27
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
 
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".
 

Similar threads

Back
Top