Padding file names with 0

Features wanted...
Post Reply
pixelsearch
Posts: 37
Joined: 21 May 2018 18:45

Padding file names with 0

Post by pixelsearch »

Hi everybody
I got a question about file renaming. In a folder, my files are named this way, with a maximum of 3 digits before the extension, here is a short example :
1.txt
5.txt
64.txt
98.txt
125.txt
496.txt

The goal is to have them renamed like the following, padded with 0 and all files having exactly 4 digits before the extension :
0001.txt
0005.txt
0064.txt
0098.txt
0125.txt
0496.txt

Using XYplorer, I couldn't find a way to do it with 1 pass only, so I did it with 2 passes, like this :

1st pass : File => Rename Special => Batch Rename...
Pattern: 000*
Intermediate result :
0001.txt
0005.txt
00064.txt
00098.txt
000125.txt
000496.txt

2nd pass: : File => Rename Special => RegExp Rename..
Pattern: .*(\d{4}) > $1
Final result (correct) :
0001.txt
0005.txt
0064.txt
0098.txt
0125.txt
0496.txt

Do you think there is a way with XYplorer to get the final result with 1 pass only ?
Thanks

highend
Posts: 13333
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: Padding file names with 0

Post by highend »

Didn't try to use the /cut option but scripting it would always be possible

If they are all in the same folder and selected...

Code: Select all

    $files = regexreplace(<get SelectedItemsNames>, "^(\d)", "000$1");
    $files = regexreplace($files, "(\d+?)(\d{4}\.[^.]+)$", "$2");
    rename "l", $files;
One of my scripts helped you out? Please donate via Paypal

admin
Site Admin
Posts: 60618
Joined: 22 May 2004 16:48
Location: Win8.1 @100%, Win10 @100%
Contact:

Re: Padding file names with 0

Post by admin »

Nice task. In the next beta you can do it using this pattern: <pad 8 0>*
Attachments
BatchPad.png
BatchPad.png (8.16 KiB) Viewed 298 times

highend
Posts: 13333
Joined: 06 Feb 2011 00:33
Location: Win Server 2022 @100%

Re: Padding file names with 0

Post by highend »

@Don

I'd say something like: <pad 4 0>* would be better (while it has to ignore extensions).

Otherwise things like this wouldn't work:

Code: Select all

1.avi
5.mp4
64.mpeg
98.mkv
One of my scripts helped you out? Please donate via Paypal

admin
Site Admin
Posts: 60618
Joined: 22 May 2004 16:48
Location: Win8.1 @100%, Win10 @100%
Contact:

Re: Padding file names with 0

Post by admin »

Good point! But I could handle it using the variant <padbase 4 0>*.
Attachments
BatchPadBase.png
BatchPadBase.png (7.78 KiB) Viewed 292 times

pixelsearch
Posts: 37
Joined: 21 May 2018 18:45

Re: Padding file names with 0

Post by pixelsearch »

Thank you both for your answers and have a great day

admin
Site Admin
Posts: 60618
Joined: 22 May 2004 16:48
Location: Win8.1 @100%, Win10 @100%
Contact:

Re: Padding file names with 0

Post by admin »

FYI, the next version will do some useful number padding:
Attachments
BatchPadNum2.png
BatchPadNum2.png (8.96 KiB) Viewed 255 times

pixelsearch
Posts: 37
Joined: 21 May 2018 18:45

Re: Padding file names with 0

Post by pixelsearch »

Thanks Don for the quick update. I just tried last beta (25.60.0110_beta_noinstall)
Then Batch Rename with the new syntax <padbase 4 0>* works great on my initial example and also on highend's example (extensions with different length like .txt .mpeg etc...)

Next version seems promising too, as shown in your last post, great job !

admin
Site Admin
Posts: 60618
Joined: 22 May 2004 16:48
Location: Win8.1 @100%, Win10 @100%
Contact:

Re: Padding file names with 0

Post by admin »

Great. :tup: The next version will bring a revised syntax. Check it out, you will probably have to change your patterns a little bit.

pixelsearch
Posts: 37
Joined: 21 May 2018 18:45

Re: Padding file names with 0

Post by pixelsearch »

Hi Don
No problem with the revised syntax with beta 25.60.0111 , all cases seem to be covered now.
Glad you got rid of several variable names (pad padbase padnumr ...) to keep only 1 variable name (pad) with flags. I wanted to discuss that very question with you in my last post but finally I thought "hey, who am I to start this kind of programming discussion with Don" and see how today you dropped all the variable names by yourself, to keep only 1 variable name : pad :)

I wondered if there's a way to get the shortest syntax possible, when applied to the batch renaming menu, something like <pad 5 0> without any flags, but it's a bad idea as shown in the following example :

Code: Select all

Original file name is F_1.txt
<pad 5 0 b>*  =>  00F_1.txt
<pad 5 0 n>*  =>  F_00001.txt
So we have to indicate at least a flag to differentiate these 2 cases, as Xyplorer won't know how to treat a shorter syntax like <pad 5 0> when applied to Batch renaming.

Which leads to a new question : in the log of the last beta, Batch renaming part, you indicate a pattern like <pad 4 0 bnr>* but isn't the b flag superfluous in this case and <pad 4 0 nr>* will always behave like <pad 4 0 bnr>* , no matter digits are found in the file name ?

If you think the b flag is superfluous when the n (or nr) flag is present, then the only 3 flag possibilities for batch remaning could be :
b alone
n alone
nr alone

without the need of ever using the combination bn or bnr . Could you share your opinion about this ?
Thanks

admin
Site Admin
Posts: 60618
Joined: 22 May 2004 16:48
Location: Win8.1 @100%, Win10 @100%
Contact:

Re: Padding file names with 0

Post by admin »

Without bnr this would not work because there is a number in the extension:

Code: Select all

     - Pattern: <pad 4 0 bnr>*        = (only the right-most number in the base is padded)
        Old Name:                     New Name:
          1.FC 1 vs FC Porto.mp4        1.FC 0001 vs FC Porto.mp4
          1.FC 20 vs FC Porto.mp4       1.FC 0020 vs FC Porto.mp4
          1.FC 300 vs FC Porto.mp4      1.FC 0300 vs FC Porto.mp4

jupe
Posts: 2805
Joined: 20 Oct 2017 21:14
Location: Win10 22H2 120dpi

Re: Padding file names with 0

Post by jupe »

I have noticed a crash can occur if for example you type in the address bar an empty variable and then pad, while this may not be something that people would do intentionally, it could still occur, to repro in fresh,

Enter something like the following in the AB: <a><pad 1 XY will crash at this point, same in LF box.

My XY even crashes if I just have that string on the clipboard and right click on the breadcrumb bar, which made me crazily test paste and go, which shows an error instead of the crash, not sure if it is useful.

2024-03-14_115906.png
2024-03-14_115906.png (16.56 KiB) Viewed 152 times

admin
Site Admin
Posts: 60618
Joined: 22 May 2004 16:48
Location: Win8.1 @100%, Win10 @100%
Contact:

Re: Padding file names with 0

Post by admin »

:blackstorm: Yes.

Post Reply