Script - adding Incremental Numbers

Advanced Renamer forum
#1 : 25/12-21 04:17
MaxEnrik
MaxEnrik
Posts: 12
I want to add incremental numbers (001) to the end of the bunch files.

Currently I use:
return str + item.index;

I need to start from 1, but the .index is starting from 0:
0


25/12-21 04:17
#2 : 25/12-21 22:56
David Lee
David Lee
Posts: 1125
return str + ('000' + (item.index + 1)).slice(-3);



25/12-21 22:56
#3 : 26/12-21 13:29
MaxEnrik
MaxEnrik
Posts: 12
Very nice! Thank you so much!

(But it still starts from 0, not 1.)

In the 'Replace > Replace with <Inc Nr:1>' this is automatically choosing counts digits like below.
If we have 9 pictures - digits like this: 0-9.
If we have 99 pictures - digits like this: 00-99.
If we have 999 pictures - digits like this: 000-999.

Is it possible to do it so? Just not manually choosing digits as I chose '000'.

(Hope I explained well - English isn't my native language.)


26/12-21 13:29 - edited 26/12-21 13:46
#4 : 26/12-21 15:43
David Lee
David Lee
Posts: 1125
Reply to #3:
I'm sorry - your question does not make any sense at all. Try posting an example of what you are trying to achieve.

Your original question described a script: "str + item.index " will add the item number of each file in the list starting with zero. If you simply add 1 to each number : " str + (item.index + 1)" then the numbering MUST start from 1 so I do not understand why you say it doesn't. You have to enclose this statement in parenthesis otherwise "str + item.index + 1" will add the character "1" to the end of the string plus item number.

The tag "<Inc Nr:1>" also adds incrementing numbers starting from 1 - NOT zero - so again your comments puzzle me.


26/12-21 15:43 - edited 26/12-21 15:44
#5 : 26/12-21 15:57
MaxEnrik
MaxEnrik
Posts: 12
Reply to #4:

Currently, I am using the code below.

var rp1 = /-\d+(\d{2})$/;
var nbn = item.newBasename;
var nn1 = nbn.replace(rp1, '_');
return nn1 + ('00' + (item.index + 1)).slice(-2);

// I don't want to write '00' and nor '-2' in slice()
// This code works perfectly, but I don't need to manually change '00', '-2' each time I want to use the script.

I am just looking to do it automatically. And need to use just the script for it.


26/12-21 15:57
#6 : 26/12-21 17:14
David Lee
David Lee
Posts: 1125
Reply to #5:
I'm sure this question would not make any more sense if you wrote it in your native language.

We cannot read your mind - JUST TELL US WHAT YOU WANT TO DO AND GIVE BEFORE AND AFTER EXAMPLES!!!!


26/12-21 17:14
#7 : 26/12-21 18:06
MaxEnrik
MaxEnrik
Posts: 12
Reply to #6:

I need to use the Script to rename files or folders. I am changing these numbers regularly.

I used this script last time, and there were over 120 images - so I used triple 0.
return nn1 + ('000' + (item.index + 1)).slice(-3);

Now I need to rename the 14 images - I have to use double 0.
return nn1 + ('00' + (item.index + 1)).slice(-2);
https://i.snipboard.io/weDNB7.jpg

Hope I explained well, if not sorry for your time.
I didn't mind to bother someone else.
Have a good one.


26/12-21 18:06
#8 : 27/12-21 10:47
David Lee
David Lee
Posts: 1125
Reply to #7:
You do not need to use a script - just use a New Name method...

New Name: <Substr:1:->_<Inc Nr:1>



27/12-21 10:47
#9 : 27/12-21 14:17
MaxEnrik
MaxEnrik
Posts: 12
Reply to #8:

It's part of a big and complex script. (private)
That is why I have to use the script.


27/12-21 14:17
#10 : 27/12-21 14:25
MaxEnrik
MaxEnrik
Posts: 12
Reply to #8:

I found what I was looking for from your responses to others' concerns.
app.parseTags("<Inc Nr:1>")

Thank you so much!


27/12-21 14:25 - edited 27/12-21 14:26