Number Padding with Zeros (existing files)

Post any Bulk Rename Utility support requirements here. Open to all registered users.

Number Padding with Zeros (existing files)

Postby lithiumus » Wed May 03, 2017 3:54 pm

I've seen the other pose on number padding but correct me if I'm wrong, I might have a different situation...

I've got existing files that have numbers near the end of the filename with Brackets that I would like to pad with zeros. I do not want to remove the numbers or change any of them, just add zero padding. So if there is a sequence (1), (2), (4), (5) and the digits go as high as (1000), I'd like to change them to (0001), (0002), (0004), (0005). Can this be done? Thanks for your help!
lithiumus
 
Posts: 2
Joined: Wed May 03, 2017 3:48 pm

Re: Number Padding with Zeros (existing files)

Postby lithiumus » Wed May 03, 2017 5:45 pm

OK. After some research and playing around with Regex, I was able to get what I needed using BRU and Regex. It requires multiple passes but honestly, after 3 passes you are basically renaming 1000 files so it's worth it.

I used some of the info from the previous posts. My numbers were inside brackets so I used \( but you can use other required characters that help you with the groupings...

Regex
Match
(.+\()(\d\))

.+ matches all characters
\( up to and including the open bracket "("

That's the first group

\d any digit (single digit)
\) up to and including the closed bracket ")"

That's the second group. For the first pass, this will get all the single character digits. Simply insert an additional \d for every digit... tens, hundreds as needed.

Replace
\10\2

\10 Prepend the first group, add a zero
\2 append the second group

So run it with

(.+\()(\d\))
\10\2

to get all the single digits then...

(.+\()(\d\d\))
\10\2

to get all the double digits then if needed...

(.+\()(\d\d\\d))
\10\2

to get all the triple digits.

There is probably a more elegant solution but this is what I hacked up quickly that works...
lithiumus
 
Posts: 2
Joined: Wed May 03, 2017 3:48 pm

Re: Number Padding with Zeros (existing files)

Postby Admin » Thu May 04, 2017 1:54 am

There's the possibility to do all with one pass using Javascript , see Special (14). But if one pass is not required, your solution works just as well!
Admin
Site Admin
 
Posts: 1521
Joined: Tue Mar 08, 2005 8:39 pm

Re: Number Padding with Zeros (existing files)

Postby KenP » Thu May 04, 2017 9:03 am

Assuming you want to end up with 4 digits between the parenthesis in each file-name, i.e. (0001), (0010), (0100), this can be done with regex in 2 passes.

RegEx (1)
Match: (.*\()(\d*\))
Replace: \1000\2

Rename
Reset

RegEx (1)
Match: (.*\()\d*(\d{4}\))
Replace: \1\2
KenP
 
Posts: 198
Joined: Sat Jul 30, 2016 11:25 am


Return to BRU Support