Replace specific digit in each filename?

Bulk Rename Utility How-To's

Replace specific digit in each filename?

Postby lordpontiff » Wed May 12, 2021 9:35 pm

I was wondering how I should go about this.

Specifically, I want to change the underlined character in each file from a 2 to an 8.

7AB50E44-1ABE787D-5E53A204-C0

I can't just use basic match and replace or translation as many of the files have multiple '2's in them which need to remain unchanged.. But all of the files have the same amount of characters in them.

Thanks...
lordpontiff
 
Posts: 3
Joined: Wed May 12, 2021 9:24 pm

Re: Replace specific digit in each filename?

Postby Luuk » Wed May 12, 2021 10:34 pm

If the 24th-character is always 2, then settings like...
Remove(5) with From=24 and To=24
Add(7) with Insert=8 and At=24
Filters(12) with Name Min/Max=33 (for 3-character extensions)

If the 24th-character is sometimes 2, then RegEx(1) with a Match and Replace like...
^(.{23})2(.{5})$
\18\2
Luuk
 
Posts: 690
Joined: Fri Feb 21, 2020 10:58 pm

Re: Replace specific digit in each filename?

Postby lordpontiff » Sat May 15, 2021 8:50 pm

Awesome, thank you.
lordpontiff
 
Posts: 3
Joined: Wed May 12, 2021 9:24 pm

Re: Replace specific digit in each filename?

Postby lordpontiff » Wed Sep 20, 2023 1:40 am

Luuk wrote:If the 24th-character is always 2, then settings like...
Remove(5) with From=24 and To=24
Add(7) with Insert=8 and At=24
Filters(12) with Name Min/Max=33 (for 3-character extensions)

If the 24th-character is sometimes 2, then RegEx(1) with a Match and Replace like...
^(.{23})2(.{5})$
\18\2


Necrobumping here, but hoping for some help.

For the regex example, how would I switch it to replace a 7 with an 8, instead of replacing 2 with 8? I tried changing the underlined 2 to 7, but that broke it, and I'm not sure why or how it works exactly.

I need to use the regex because sometimes the 24th digit isn't 2, and in that case I need it to not be renamed...

Thanks, hopefully someone sees this.
lordpontiff
 
Posts: 3
Joined: Wed May 12, 2021 9:24 pm

In 29-char names, if 24th-char is 7, replace it with 8

Postby Luuk » Wed Sep 20, 2023 3:50 am

Its just a bad copy/paste, but this might make it easier to read and edit...
^(.{23})[7](.{5})$
\18\2

^ ======= The very beginning.
(.{23}) === 23 characters (grouped) for using \1 in the replace.
[7] ====== One 7... You might prefer [27] to say one 2 or 7.
(.{5}) ==== 5 characters (grouped) for using \2 in the replace.
$ ======= The very end, so only 29-character names can be edited.
Luuk
 
Posts: 690
Joined: Fri Feb 21, 2020 10:58 pm


Return to How-To