Regex Rename

samintz

Scott Mintz
May 20, 2008
1,503
16
Solon, OH, USA
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
 
May 20, 2008
11,400
99
Syracuse, NY, USA
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
Thread starter Title Forum Replies Date
F %@regex["^-","-a"] returns 0, "^-" =~ "-a" is false (no match) Support 4
JohnQSmith Regex renaming Support 2
vefatica TPIPE: unbalanced escaped quotes in a regex? Support 5
rps Regex problem: \xnn not recognized as a hex character Support 0
old coot Regex problem: \xnn not recognized as a hex character Support 12
R Regex using ^ Support 2
T Regex engine doesn't recognize native DOS line endings Support 2
P Simple RegEx copy Support 9
samintz WAD Regex Analyzer Support 1
D How to? Use typed envars using regex. Support 3
P Renaming with a RegEx Support 1
R How to? use @everything perl regex Support 2
C v18 regex help please Support 1
C Font of RegEx Analyzer Support 0
D Regex problem Support 17
mikea How to? Regex match when there shouldn't be (?) Support 18
JohnQSmith Fixed Copying with regex (several issues) Support 7
D Help needed to get a regex to work Support 3
thedave WAD Regex match on \h Support 5
Ville Regex & conditionals Support 9
vefatica @REGEX: behavior vs. documentation Support 2
vefatica @REGEX revisited Support 4
vefatica @REGEX question Support 6
vefatica Regex question Support 5
B Regex and Replace Support 6
Stefano Piccardi detecting BOM, FFIND multibyte regex Support 18
dcantor FFIND syntax -- is /E"regex" /X supported? Support 2
P Renaming files with regex. Support 6
B "Fun" with DO and Regex Support 12
P Need to use a regex in a "for" loop. Support 54
Joe Caverly Rename file that begins with Emoji Support 7
C Documentation Help Nit. REN / RENAME Support 0
C How to? rename files with spaces Support 8
R How to? Replace in Rename Support 9
Phileosophos WAD Can't rename files in subfolders Support 1
P Rename files with ampersand in the name Support 1
C How to rename files with "(" Support 14
M How to? File rename problem... Support 11
D Folders pane display problem after rename Support 0
fpefpe How to? Rename runs tree Support 10
JohnQSmith Slow network directory rename Support 8
JohnQSmith Folder pane right-click rename Support 2
A Rename Files in Chronological Order? Support 5
nikbackm Rename TC tab from command line Support 0

Similar threads