Add Zero's to the file to make 6 digit file name

Bulk Rename Utility How-To's

Add Zero's to the file to make 6 digit file name

Postby smartcard » Sat Dec 16, 2023 9:33 pm

I have a folder containing several image files, all starting with 'R-.' I would like to add leading zeros to the filenames to ensure they have a six-digit file name format.

In the following example, the first two filenames are correct, but for the remaining ones, I need to add the necessary zeros to achieve a six-digit filename. For instance:

    R-001057.jpg = good
    R-000058.jpg = good
    R-753.jpg = R-000753.jpg
    R-1054.jpg = R-001054.jpg
    R-1055.jpg = R-001055.jpg
    R-656.jpg = R-000656.jpg

Your assistance in this matter is appreciated
smartcard
 
Posts: 3
Joined: Sat Dec 16, 2023 9:25 pm

Pad "R-Digits" into "R-6Digits"

Postby Luuk » Sun Dec 17, 2023 3:37 am

To only rename jpg's, then Filters(12) could use something like *.jpg inside for the "Mask".
For 6-digits, Regex(1) needs a checkmark inside for "v2" with a "Match" and "Replace" like...
^(R-)(?=\d+$)(?X)(\G(?!^)|^R-)\K0(?=\d{6,}$)/g
${1}00000(?X)

R-1 ------------> R-000001
R-199 ---------> R-000199
R-00000009 --> R-000009
R-10000009 --> (not renamed)
Luuk
 
Posts: 706
Joined: Fri Feb 21, 2020 10:58 pm

Re: Pad "R-Digits" into "R-6Digits"

Postby smartcard » Sun Dec 17, 2023 4:12 am

Luuk wrote:To only rename jpg's, then Filters(12) could use something like *.jpg inside for the "Mask".
For 6-digits, Regex(1) needs a checkmark inside for "v2" with a "Match" and "Replace" like...
^(R-)(?=\d+$)(?X)(\G(?!^)|^R-)\K0(?=\d{6,}$)/g
${1}00000(?X)

R-1 ------------> R-000001
R-199 ---------> R-000199
R-00000009 --> R-000009
R-10000009 --> (not renamed)


Thank you so much! The process worked perfectly, just as expected

I need another help, how can I remove any characters between the last number in the file name and the extension as highlighted in the below image?
Image
smartcard
 
Posts: 3
Joined: Sat Dec 16, 2023 9:25 pm

Pad "R-digits" into "R-6Digits"

Postby Luuk » Sun Dec 17, 2023 5:12 am

Would need to edit the "Match" and "Replace" to something more like...
^(R-)(\d+).*(?X)(\G(?!^)|^R-)\K0(?=\d{6,}$)/g
${1}00000$2(?X)

R-1 ------------> R-000001
R-2Text -------> R-000002
R-199 ---------> R-000199
R-00000009 --> R-000009
R-10000009 --> (not renamed)
Luuk
 
Posts: 706
Joined: Fri Feb 21, 2020 10:58 pm


Return to How-To