Decrease fileNumber by 1

Bulk Rename Utility How-To's

Decrease fileNumber by 1

Postby bp123987 » Fri Mar 19, 2021 3:08 am

Hello,

I have following files in a directory:

userNum1022.html
userNum1023.html
userNum1024.html
userNum1025.html

and so on.
I wish to rename them to

userNum1021.html
userNum1022.html
userNum1023.html
userNum1024.html

etc. That is, decrease the indent of each fileName by one.
How to go about doing this?
p.s. - previously, I had files userNum1.html to userNum2500.html in a single directory. Due to bad formatting, I had to delete a file in the middle, userNum1021.html. To rename the remaining files, I moved the rest of the files, userNum1022.html to userNum2500.html in a separate directory. It is in this directory that I am trying to reduce the indent by one, so that I can move the newly renamed files back to the original folder, where the serial order is maintained. If the renaming can be done in the original folder itself, please do let me know, as it will save the trouble of cut-paste and create new directory etc.
Thanks.
bp123987
 
Posts: 3
Joined: Fri Mar 19, 2021 2:57 am

Re: Decrease fileNumber by 1

Postby Luuk » Fri Mar 19, 2021 4:30 am

Im thinking the easiest way, is to conduct the rename back inside the original folder with RegEx(1) and Numbering(10).
This because RegEx(1) can first destroy the ending numbers, so then Numbering(10) to put them all back in serial order.

So the RegEx(1) Match and Replace like ...
^(userNum)\d+$
\1
And the Numbering(10) to be with Mode=Suffix, Start=1, Pad=0


For the paid version, there is good example of javascript doing the math at viewtopic.php?f=2&t=4849
But must solve how to modify for this example, and maybe also removing the extra zeros for padding?
Luuk
 
Posts: 692
Joined: Fri Feb 21, 2020 10:58 pm

Re: Decrease fileNumber by 1

Postby therube » Fri Mar 19, 2021 4:13 pm

Ensure that your names are "ordered" correctly.
(Correct, I'm thinking would be from high to low; 1024..1023..1022..)

2:Name -> Remove
7:Add -> Prefix: userNum
10:Numbering -> Mode: Suffix, Start: 1024

Test & see if that looks OK, & then renames correctly.
(In Renaming Options, there is also a Reverse Order option that can help at times.)
therube
 
Posts: 1314
Joined: Mon Jan 18, 2016 6:23 pm

Re: Decrease fileNumber by 1

Postby saberanasterian » Fri Mar 19, 2021 10:27 pm

Hello. Imagine I have the same problem today, but it's a little more complicated. I have about a hundred images in PNG format and I also need to make minus one for each number. But the numbers are without straight order. They are random, but still increasing. (ffmpeg scene detection frames) Example AND how should be.
0014.png > 0013
0073 > 0072
0096 > 0095
0133 > 0132
0154 > 0153
0171 > 0170
0183 > 0182
0202 > 0201
0205 > 0204
...
2320 > 2319
2327 > 2326
2386 > 2386
As I said, there are only 104 files. Of course I can manually rename them all, but what if my video was not 1:30 seconds, but an hour ... I hope for any help or advice. Thanks.
saberanasterian
 
Posts: 2
Joined: Fri Mar 19, 2021 10:12 pm

Re: Decrease fileNumber by 1

Postby saberanasterian » Fri Mar 19, 2021 10:51 pm

saberanasterian wrote:Hello. Imagine I have the same problem today, but it's a little more complicated. I have about a hundred images in PNG format and I also need to make minus one for each number. But the numbers are without straight order. They are random, but still increasing. (ffmpeg scene detection frames) Example AND how should be.
0014.png > 0013
0073 > 0072
0096 > 0095
0133 > 0132
0154 > 0153
0171 > 0170
0183 > 0182
0202 > 0201
0205 > 0204
...
2320 > 2319
2327 > 2326
2386 > 2386
As I said, there are only 104 files. Of course I can manually rename them all, but what if my video was not 1:30 seconds, but an hour ... I hope for any help or advice. Thanks.

Upd: Done fast with another program renamer + extra needs.
saberanasterian
 
Posts: 2
Joined: Fri Mar 19, 2021 10:12 pm

Re: Decrease fileNumber by 1

Postby Luuk » Fri Mar 19, 2021 11:34 pm

Also, there is good example of javascript doing the math... viewtopic.php?f=2&t=4849
So then just changing +559 to -1 or whatever else math is needed to conduct.
Luuk
 
Posts: 692
Joined: Fri Feb 21, 2020 10:58 pm

Re: Decrease fileNumber by 1

Postby Admin » Sat Mar 20, 2021 12:43 am

Javascript:

-----------------------

function pad(n, width, z) {
z = z || '0';
n = n + '';
return n.length >= width ? n : new Array(width - n.length + 1).join(z) + n;
}

i = parseInt(name,10);
i--;
newName = pad(i,4);

-----------------------
Admin
Site Admin
 
Posts: 2343
Joined: Tue Mar 08, 2005 8:39 pm

Re: Decrease fileNumber by 1

Postby bp123987 » Sat Mar 20, 2021 6:28 am

Luuk wrote:Im thinking the easiest way, is to conduct the rename back inside the original folder with RegEx(1) and Numbering(10).
This because RegEx(1) can first destroy the ending numbers, so then Numbering(10) to put them all back in serial order.

So the RegEx(1) Match and Replace like ...
^(userNum)\d+$
\1
And the Numbering(10) to be with Mode=Suffix, Start=1, Pad=0


Thank you.
bp123987
 
Posts: 3
Joined: Fri Mar 19, 2021 2:57 am

Re: Decrease fileNumber by 1

Postby bp123987 » Sat Mar 20, 2021 6:30 am

therube wrote:Ensure that your names are "ordered" correctly.
(Correct, I'm thinking would be from high to low; 1024..1023..1022..)

2:Name -> Remove
7:Add -> Prefix: userNum
10:Numbering -> Mode: Suffix, Start: 1024

Test & see if that looks OK, & then renames correctly.
(In Renaming Options, there is also a Reverse Order option that can help at times.)


Many thanks. Much easier approach.
bp123987
 
Posts: 3
Joined: Fri Mar 19, 2021 2:57 am


Return to How-To