Comments on: Windows command-line regular expression renaming tool: RenameRegex https://nicj.net/windows-command-line-regular-expression-renaming-tool-renameregex/ Home to Nic Jansma, a software developer at Akamai building high-performance websites, apps and open-source tools. Sat, 12 Aug 2023 21:14:18 +0000 hourly 1 https://wordpress.org/?v=5.5.3 By: Pendo Seven https://nicj.net/windows-command-line-regular-expression-renaming-tool-renameregex/comment-page-1/#comment-1252130 Sat, 12 Aug 2023 21:14:18 +0000 http://nicj.net/?p=1175#comment-1252130 Not sure what happened to my comment/question that I posted (as it’s now missing), but I’ve found a solution to it myself so you don’t have to answer unless you want to. FYI, my solution was to include the grouping number is “{” and “}”, e.g. instead of “$1000$2.jpg”, it would instead be “${1}000${2}.jpg” (the second pair isn’t required, but I used it this way to be consistent).

]]>
By: Pendo Seven https://nicj.net/windows-command-line-regular-expression-renaming-tool-renameregex/comment-page-1/#comment-1252121 Sat, 12 Aug 2023 09:07:55 +0000 http://nicj.net/?p=1175#comment-1252121 Hi, I love this little app, and use it often, but have found an annoying situation I hope you have a solution for.

When using the command: k:\apps\rr.exe * “(\D+)(\d)\.jpg” “$1000$2.jpg”

To pad the filename with numbers to 4 digits with zeros, I’ve found that this works ok except when the placing the $1 at the start of any replacement filename.

I’ve tried many possible combinations of placing “^” and “$” and in the search filename text with no joy.

The below shows an example:

pic_1.jpg -> $10001.jpg
pic_2.jpg -> $10002.jpg
pic_3.jpg -> $10003.jpg
pic_4.jpg -> $10004.jpg
pic_5.jpg -> $10005.jpg
pic_6.jpg -> $10006.jpg
pic_7.jpg -> $10007.jpg
pic_8.jpg -> $10008.jpg
pic_9.jpg -> $10009.jpg

Is there a way to overcome this apparent bug?

]]>
By: Nic https://nicj.net/windows-command-line-regular-expression-renaming-tool-renameregex/comment-page-1/#comment-1248392 Wed, 02 Feb 2022 00:54:43 +0000 http://nicj.net/?p=1175#comment-1248392 In reply to Pablo Rosatti.

One thing to remember is that the search and replacement patterns are regular expressions, and a “period” (.) in a regular expression matches any character.

So this command:

rr *.txt "..txt" "2.txt"

Really means “replace [anything][anything]txt” with “.txt”.

Instead, you’ll want to escape the period so it’s taken literally:

rr *.txt "\.\.txt" ".txt"

Then it should just replace files with “..txt” in the name.

My test examples:

RR.exe *.txt " .txt" ".txt"
name with space .txt -> name with space.txt

RR.exe *.txt "\..txt" ".txt"
name with double period at end..txt -> name with double period at end.txt

Hope that helps!

]]>
By: Pablo Rosatti https://nicj.net/windows-command-line-regular-expression-renaming-tool-renameregex/comment-page-1/#comment-1248241 Mon, 06 Dec 2021 09:03:09 +0000 http://nicj.net/?p=1175#comment-1248241 To rename:
“file .ext” to “file.ext”
rr *.txt ” .txt” “.txt”
it works

To rename:
“file..ext” to “file.ext”
rr *.txt “..txt” “.txt”
It doesn’t work, I rename all the files.
What am I wrong?

]]>
By: justin https://nicj.net/windows-command-line-regular-expression-renaming-tool-renameregex/comment-page-1/#comment-1248225 Fri, 03 Dec 2021 21:15:37 +0000 http://nicj.net/?p=1175#comment-1248225 Just want to say I absolutely love this binary and thank you. I’ve written my own variants over the years; in bash, perl, python, and even cmd. But this is the easiest to just use without having to constantly remind myself of the parameters, argument order, direction of masking slashes etc.
P.s. I’ve always had a soft spot for this jscript polyglot cmd implementation of a regexp renamer also: https://github.com/Thdub/Optimize_NextGen/blob/master/Files/Utilities/JREPL.bat

]]>
By: Nic https://nicj.net/windows-command-line-regular-expression-renaming-tool-renameregex/comment-page-1/#comment-1247493 Tue, 12 Jan 2021 18:19:56 +0000 http://nicj.net/?p=1175#comment-1247493 In reply to Carlos.

The file match is based on the regex, we’re not relying on the OS matching at all.

]]>
By: Carlos https://nicj.net/windows-command-line-regular-expression-renaming-tool-renameregex/comment-page-1/#comment-1247492 Tue, 12 Jan 2021 16:59:20 +0000 http://nicj.net/?p=1175#comment-1247492 Nic, This tool is quite useful !!
I’ve one question, the “file match” part is also RegEx based or is just standard wildcard processing from operating system?
Kind regards

]]>
By: Nic https://nicj.net/windows-command-line-regular-expression-renaming-tool-renameregex/comment-page-1/#comment-1246757 Mon, 11 May 2020 14:57:50 +0000 http://nicj.net/?p=1175#comment-1246757 In reply to huynh hieu.

@huynh: I don’t think rename-regex is needed for that, but you should be able to do a loop in a batch file starting with the highest number, moving it forward by one, decrementing the number by one, moving that forward by one, etc.

]]>
By: huynh hieu https://nicj.net/windows-command-line-regular-expression-renaming-tool-renameregex/comment-page-1/#comment-1246755 Mon, 11 May 2020 13:34:09 +0000 http://nicj.net/?p=1175#comment-1246755 Hi Nic!
I need to change filenames, such as “”somethingtest01”, “somethingtest02”, …. to “somethingtest02”, “somethingtest03” (increment by 1 or an other number step)
Could you help me

]]>
By: Tom https://nicj.net/windows-command-line-regular-expression-renaming-tool-renameregex/comment-page-1/#comment-1246725 Sat, 25 Apr 2020 17:20:17 +0000 http://nicj.net/?p=1175#comment-1246725 I _LOVE_ this tool and I use it all of the time. It saves me so much time and effort in file management.

Thank you VERY much!
Tom

]]>
By: Matteo https://nicj.net/windows-command-line-regular-expression-renaming-tool-renameregex/comment-page-1/#comment-1246550 Mon, 17 Feb 2020 20:57:27 +0000 http://nicj.net/?p=1175#comment-1246550 Works! Thanks!

]]>
By: Nic https://nicj.net/windows-command-line-regular-expression-renaming-tool-renameregex/comment-page-1/#comment-1246547 Fri, 14 Feb 2020 13:17:56 +0000 http://nicj.net/?p=1175#comment-1246547 Hi @Matteo!

For UNC paths, can you “pushd” to them first so the folder is mapped as a local letter?

I’ve just verified that this command should work:

RR *.txt "([0-9]+)_([a-z]+)" "$2_$1" /p
123_xyz.txt -> xyz_123.txt (pretend)

]]>
By: Matteo https://nicj.net/windows-command-line-regular-expression-renaming-tool-renameregex/comment-page-1/#comment-1246516 Thu, 30 Jan 2020 12:39:34 +0000 http://nicj.net/?p=1175#comment-1246516 Hi Nic, I need your help again if you can.
I’d like to use your awesome tool in a net like “\\NAS\folder\” but windows command line doesn’t accept UNC directories. I tried to use Power shell but it doesn’t work properly.

I need to rename file like in your example: “123_xyz.txt” to “xyz_123.txt”.

.\RR.exe *.txt "([0-9]+)_([a-z]+)" "$2_$1" showed the help, so I modified in this:
.\RR.exe *.txt "(?[0-9]+)_(?[a-z]+)" "${1}_${2}" but the result is the following:
124_xyz.txt -> _.txt (pretend)

Where am I wrong?
Thank you very much

]]>
By: Nic https://nicj.net/windows-command-line-regular-expression-renaming-tool-renameregex/comment-page-1/#comment-1246446 Wed, 08 Jan 2020 14:04:09 +0000 http://nicj.net/?p=1175#comment-1246446 In reply to Peter.

Hi Peter! I hope to have some time soon to add that option (and others). I’ve filed some Github issues to track this: https://github.com/nicjansma/rename-regex/issues

]]>
By: Peter https://nicj.net/windows-command-line-regular-expression-renaming-tool-renameregex/comment-page-1/#comment-1246434 Tue, 07 Jan 2020 14:22:34 +0000 http://nicj.net/?p=1175#comment-1246434 As I read in comments that RR does not pay attention to Upper vs. Lower case.
I need this option to replace e.g. ” rel. ” by ” Rel. ” in filenames.

You have the recommendation to change this line 56 in Program.cs:

Hmm, I am not a programmer. If it that easy: could you provide a changed RR version WITH upper/lowercase attention?

Thank you
Peter

]]>
By: Nic https://nicj.net/windows-command-line-regular-expression-renaming-tool-renameregex/comment-page-1/#comment-1246368 Sat, 07 Dec 2019 03:46:33 +0000 http://nicj.net/?p=1175#comment-1246368 In reply to Jim Anderson.

@Jim – Feel free to open an Issue on the Github project page or a Pull Request if you’re inclined!

https://github.com/nicjansma/rename-regex/

]]>
By: Jim Anderson https://nicj.net/windows-command-line-regular-expression-renaming-tool-renameregex/comment-page-1/#comment-1246194 Fri, 27 Sep 2019 00:01:21 +0000 http://nicj.net/?p=1175#comment-1246194 I love this tool! Quick and easy, the only thing lacking for me is the ability to also rename *folders* – is that something that could be added?

]]>
By: Nic https://nicj.net/windows-command-line-regular-expression-renaming-tool-renameregex/comment-page-1/#comment-1245610 Wed, 01 May 2019 01:49:09 +0000 http://nicj.net/?p=1175#comment-1245610 In reply to computerprep.

You could use something like this maybe, with a replacement pattern?

rr * “(.*set[0-9]+img[0-9]+).*” “$1” /p

That would remove everything after set#img#

]]>
By: computerprep https://nicj.net/windows-command-line-regular-expression-renaming-tool-renameregex/comment-page-1/#comment-1245557 Thu, 18 Apr 2019 14:39:51 +0000 http://nicj.net/?p=1175#comment-1245557 This could fit my need perfectly!!! I’m just struggling to implement in my test folder before rolling out.

I have a filename pattern like .*set.*[0-9]img.*[0-9].*
To explain that in plain english (if my regex is off) the filenames start with any string of unknown characters (including periods, hyphens, commas, apostrophes, etc) followed by a specific pattern set#img# (where the number is between 1-4 digits long), followed by another string of unknown characters.

I need to remove all characters after the set#img# pattern in the middle. Any advice?

]]>
By: Matteo https://nicj.net/windows-command-line-regular-expression-renaming-tool-renameregex/comment-page-1/#comment-1245014 Fri, 14 Sep 2018 07:18:26 +0000 http://nicj.net/?p=1175#comment-1245014 It works perfectly! Great!

]]>
By: Nic https://nicj.net/windows-command-line-regular-expression-renaming-tool-renameregex/comment-page-1/#comment-1245011 Fri, 14 Sep 2018 00:46:25 +0000 http://nicj.net/?p=1175#comment-1245011 Try this instead:


RR.exe * "^(.*)$" "prefix$1"
RR.exe * "^(.*)$" "$1suffix"

]]>
By: Matteo https://nicj.net/windows-command-line-regular-expression-renaming-tool-renameregex/comment-page-1/#comment-1244990 Thu, 06 Sep 2018 07:28:21 +0000 http://nicj.net/?p=1175#comment-1244990 Thank you Nic. But when I use the prefix code I have the prefix added both at the beginning and at the end of the file name.
FILENAME.ZIP –> prefixFILENAME.ZIPprefix

The suffix code added the suffix two times
FILENAME.ZIP –> FILENAME.ZIPsuffixsuffix

I tried to edit the code, but it always added something at the end.

]]>
By: Nic https://nicj.net/windows-command-line-regular-expression-renaming-tool-renameregex/comment-page-1/#comment-1244961 Wed, 22 Aug 2018 14:15:16 +0000 http://nicj.net/?p=1175#comment-1244961 @Matteo: You could use a regex like:

RR.exe * "(.*)" "prefix$1"
RR.exe * "(.*)" "$1suffix"

]]>
By: Matteo https://nicj.net/windows-command-line-regular-expression-renaming-tool-renameregex/comment-page-1/#comment-1244944 Sat, 11 Aug 2018 10:58:52 +0000 http://nicj.net/?p=1175#comment-1244944 Great tool.
But is there a way to add a prefix or a suffix to a file names?

]]>
By: ozz https://nicj.net/windows-command-line-regular-expression-renaming-tool-renameregex/comment-page-1/#comment-1221667 Sun, 07 Jun 2015 16:12:37 +0000 http://nicj.net/?p=1175#comment-1221667 Hi,
nice tool. I like it.
btw. the code seems to be updated, but the binary unfortunately not. *hint*

]]>
By: Herm https://nicj.net/windows-command-line-regular-expression-renaming-tool-renameregex/comment-page-1/#comment-1221584 Tue, 17 Mar 2015 23:40:24 +0000 http://nicj.net/?p=1175#comment-1221584 Thanks Much! Great simple batch rename utility, helps a lot as GUIs couldnt rename/replace extensions that needed to be truncated

]]>
By: WCWedin https://nicj.net/windows-command-line-regular-expression-renaming-tool-renameregex/comment-page-1/#comment-82719 Tue, 05 Feb 2013 22:02:16 +0000 http://nicj.net/?p=1175#comment-82719 I’m commenting to say that this little program perfectly met my needs in a minor emergency and got me out of a tight spot! Thanks!

]]>
By: Nic https://nicj.net/windows-command-line-regular-expression-renaming-tool-renameregex/comment-page-1/#comment-9076 Mon, 08 Oct 2012 19:46:20 +0000 http://nicj.net/?p=1175#comment-9076 @CZNeo

The app currently ignores case in the RegEx, but you can change this line 56 in Program.cs:

// rename via a regex
string fileNameAfter = Regex.Replace(fileName, nameSearch, nameReplace, RegexOptions.IgnoreCase);

To remove RegexOptions.IgnoreCase:


// rename via a regex
string fileNameAfter = Regex.Replace(fileName, nameSearch, nameReplace);

]]>
By: CZNeo https://nicj.net/windows-command-line-regular-expression-renaming-tool-renameregex/comment-page-1/#comment-9075 Mon, 08 Oct 2012 19:31:04 +0000 http://nicj.net/?p=1175#comment-9075 Hi,

I need to rename a couple of files that would contain only the lowercase english chars (ie. ŽČs.jpg -> zcs.jpg)

Is that possible?

Thx,

CZNeo

]]>
By: Giri https://nicj.net/windows-command-line-regular-expression-renaming-tool-renameregex/comment-page-1/#comment-7829 Wed, 13 Jun 2012 07:11:16 +0000 http://nicj.net/?p=1175#comment-7829 For the fist case, windows rename command can do the job.
See rename file extensions

For all other cases, this tool would help.

]]>
By: Nic https://nicj.net/windows-command-line-regular-expression-renaming-tool-renameregex/comment-page-1/#comment-7178 Thu, 02 Feb 2012 18:14:58 +0000 http://nicj.net/?p=1175#comment-7178 It doesn’t currently, but that would be a fairly simple update to the code. Are you comfortable making changes? Feel free to contribute edits at https://github.com/nicjansma/rename-regex, or even just open an issue there as a feature request.

]]>
By: Wesley https://nicj.net/windows-command-line-regular-expression-renaming-tool-renameregex/comment-page-1/#comment-7170 Thu, 02 Feb 2012 02:31:09 +0000 http://nicj.net/?p=1175#comment-7170 Is there any chance to make it go into folders recursively? Thanks

]]>
By: Nic https://nicj.net/windows-command-line-regular-expression-renaming-tool-renameregex/comment-page-1/#comment-7168 Wed, 01 Feb 2012 17:16:57 +0000 http://nicj.net/?p=1175#comment-7168 Thanks Phil, great catch! Fixed the post.

]]>
By: Phil Quinn https://nicj.net/windows-command-line-regular-expression-renaming-tool-renameregex/comment-page-1/#comment-7166 Wed, 01 Feb 2012 12:44:30 +0000 http://nicj.net/?p=1175#comment-7166 Hi — thanks for this. I noticed a small typo in this line: Rename files in the pattern of “124_xyz.txt” to “xyz_123.txt”:

]]>