Randomized numbering problem part 2: item number >100?!

Advanced Renamer forum
#1 : 26/06-19 19:22
Alex Foster
Alex Foster
Posts: 11
Hi again (David?),

your randomizing file numbers script works like a charm - until today when I tried to renumber 104 files in a folder -- but what came out was not the files with 1 to 104 at the beginning but actually it started with 00, then 01, 02 and 03 were assigned twice and only then did it continue with 04 to 99.

How do I have to modify the script so that the files are numbered 001 to 104, please?

Thanks so much in advance!


26/06-19 19:22
#2 : 27/06-19 07:52
David Lee
David Lee
Posts: 1125
You just need to modify the code in the "return" statement to return 3 digits rather than just 2.

The code as it is will correctly be generating random numbers in any range but only returning the final two digits when padded with up to one leading zero.

Thus the existing statement "return ("0" + (x + 1)).slice(-2)" adds two zeroes to the beginning of each number and the method "slice(-2)" returns just the final two digits. So numbers 100, 101, 102, 103 & 104 will return 00, 01, 02, 03 & 04, as you are seeing.

So to allow for numbers ≥100 you need:

return ("00" + (x + 1)).slice(-3)+ " " + item.name;


27/06-19 07:52 - edited 27/06-19 08:02
#3 : 27/06-19 14:35
Alex Foster
Alex Foster
Posts: 11
Reply to #2:
In fact I tried to alter it myself but would never have thought of the "slice" bit.

You're a genius, thank you so very very much again, David. Your work is most appreciated.


27/06-19 14:35