Rescursive numerate files in folders. Starting to 1 in each folder

Advanced Renamer forum
#1 : 27/12-21 09:28
teter
teter
Posts: 1
I have multiple folders. Need to numerate files in each folder, but starting in each folder with 1.

Ex:

folder 1
sadfsf num001
sdfsd num002
sdfds num003

folder 2
sdfsd num001
sdfst num002
sdfsd num003

When i try to add all folders, the numeration continues.. I don't like this

folder 1
asda num001
sdfsd num002

folder 2
sdfgd num003
sdfds num004



27/12-21 09:28
#2 : 27/12-21 12:35
David Lee
David Lee
Posts: 1125
You will need to use a script method.

I'm assuming here that you are simply adding space + incrementing number to each original file name.

Define an object in the Pre-batch Script to keep count of how many files have been enumerated in each folder (works like an array indexed by the folder name):

var filesInFolder = {};

Now in the main script check if the object element corresponding to the item's folder name already exists. If not set it to 1, otherwise increment its value:

folder = app.parseTags("<DirName:1>");
if(num = filesInFolder[folder]) num++; else num = 1;
filesInFolder[folder] = num;
return item.name + " " + ("00" + num).slice(-3);

Note: in the return statement ("00" + num).slice(-3) zero-pads the incrementing number to 3 digits by prefixing 2 zero characters to the number and then keeping only the final 3 characters.


27/12-21 12:35
#3 : 03/01-22 03:41
MaxEnrik
MaxEnrik
Posts: 12
Reply to #2:

In this case, is it possible to use ( app.parseTags("<Inc Nr:1>") ) with 'num'?


03/01-22 03:41