Fix Numbering Within () Parentheses

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

Fix Numbering Within () Parentheses

Postby farfromnoise » Sat Nov 05, 2011 7:04 pm

I have several files that are named File Name (1), File Name (2)...File Name (20). I would like to change them all to have double digit number so it can read either File Name (01) or File Name 01. I don't really care about the parentheses but they don't sort in the proper order without the zero filled single digits. Sometimes the filename is 2 words and sometimes it's 3 or even more. And in a few instances the numbering goes past 99 so I would need to fill up to three digits but I think I can figure that out if I can get help with the first part.

Thanks for any and all help.
farfromnoise
 
Posts: 1
Joined: Sat Nov 05, 2011 6:57 pm

Re: Fix Numbering Within () Parentheses

Postby bitmonger » Sun Nov 06, 2011 8:47 pm

I can tell you how to do this in BRU.
Assuming that all you filenames are the pattern shown and that there is only a single occurrence of (x) or (xx) etc. per filename you can do it with a regex in a single pass.
If you have some that are (x), some that are (xx) and some that are (xxx) then you can do it in 2 passes; one to add zero to all (x) to make (0x), and in the second pass to make all (xx) into (0xx)

Use Regex(1) field (Include Ext. NOT checked!)

Match: ^([^(]+\()(\d\).*)
Replace: \10\2

The ^([^(]+\() matches the first part of the filename up to and including the opening parenthesis and captures it in \1.
The (\d\).*) matches a single number, a closing parenthesis and the rest of the filename and captures it in \2
The replace \10\2 puts in the first captured part - the \1, then we add a zero 0, and the rest is tacked on from \2 -

This will change all the single digit (x) into (0x), but it will NOT match or change any (xx).

If you had some (xxx) numbers as well, now you will have only (xx) and (xxx). (All the (x) will have been converted to (xx).)
So to change these (xx) we need to do a second pass.


Second pass:
Now change
Match: ^([^(]+\()(\d\d\).*)
Replace: \10\2

Note the only change was an added \d in (\d\d\).*)
This will make all (xx) into (0xx). It will NOT match or change any existing (xxx).

This can of course be extended to as many digits as you need, expanding the regex each time by one \d.

Hope this helps,
Bit
bitmonger
 
Posts: 50
Joined: Sat Sep 22, 2007 5:05 am


Return to BRC Support