Page 1 of 1

Decrease fileNumber by 1

PostPosted: Fri Mar 19, 2021 3:08 am
by bp123987
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.

Re: Decrease fileNumber by 1

PostPosted: Fri Mar 19, 2021 4:30 am
by Luuk
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?

Re: Decrease fileNumber by 1

PostPosted: Fri Mar 19, 2021 4:13 pm
by therube
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.)

Re: Decrease fileNumber by 1

PostPosted: Fri Mar 19, 2021 10:27 pm
by saberanasterian
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.

Re: Decrease fileNumber by 1

PostPosted: Fri Mar 19, 2021 10:51 pm
by saberanasterian
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.

Re: Decrease fileNumber by 1

PostPosted: Fri Mar 19, 2021 11:34 pm
by Luuk
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.

Re: Decrease fileNumber by 1

PostPosted: Sat Mar 20, 2021 12:43 am
by Admin
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);

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

Re: Decrease fileNumber by 1

PostPosted: Sat Mar 20, 2021 6:28 am
by bp123987
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.

Re: Decrease fileNumber by 1

PostPosted: Sat Mar 20, 2021 6:30 am
by bp123987
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.