Padding file names with 0
-
- Posts: 37
- Joined: 21 May 2018 18:45
Padding file names with 0
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
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
Re: Padding file names with 0
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...
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
-
- Site Admin
- Posts: 60632
- Joined: 22 May 2004 16:48
- Location: Win8.1 @100%, Win10 @100%
- Contact:
Re: Padding file names with 0
Nice task. In the next beta you can do it using this pattern:
<pad 8 0>*
- Attachments
-
- BatchPad.png (8.16 KiB) Viewed 314 times
FAQ | XY News RSS | XY Twitter
Re: Padding file names with 0
@Don
I'd say something like:
Otherwise things like this wouldn't work:
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
-
- Site Admin
- Posts: 60632
- Joined: 22 May 2004 16:48
- Location: Win8.1 @100%, Win10 @100%
- Contact:
Re: Padding file names with 0
Good point! But I could handle it using the variant
<padbase 4 0>*
.- Attachments
-
- BatchPadBase.png (7.78 KiB) Viewed 308 times
FAQ | XY News RSS | XY Twitter
-
- Posts: 37
- Joined: 21 May 2018 18:45
Re: Padding file names with 0
Thank you both for your answers and have a great day
-
- Site Admin
- Posts: 60632
- Joined: 22 May 2004 16:48
- Location: Win8.1 @100%, Win10 @100%
- Contact:
Re: Padding file names with 0
FYI, the next version will do some useful number padding:
- Attachments
-
- BatchPadNum2.png (8.96 KiB) Viewed 271 times
FAQ | XY News RSS | XY Twitter
-
- Posts: 37
- Joined: 21 May 2018 18:45
Re: Padding file names with 0
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 !
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 !
-
- Site Admin
- Posts: 60632
- Joined: 22 May 2004 16:48
- Location: Win8.1 @100%, Win10 @100%
- Contact:
Re: Padding file names with 0
Great. The next version will bring a revised syntax. Check it out, you will probably have to change your patterns a little bit.
FAQ | XY News RSS | XY Twitter
-
- Posts: 37
- Joined: 21 May 2018 18:45
Re: Padding file names with 0
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 :
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
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
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
-
- Site Admin
- Posts: 60632
- Joined: 22 May 2004 16:48
- Location: Win8.1 @100%, Win10 @100%
- Contact:
Re: Padding file names with 0
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
FAQ | XY News RSS | XY Twitter
Re: Padding file names with 0
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:
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.
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.