Name collision rule: Append incrementing number

Advanced Renamer forum
#1 : 08/04-23 11:49
David Tiede
David Tiede
Posts: 4
Hey,
it's a repost, because I can't reply to the old post: https://www.advancedrenamer.com/forum_thread?for um_id=4444

I want to do the following:
As a name collision rule, I want to append an incrementing number.

Example:
Foo.txt
Foo.txt
Bar.txt
Bar.txt
Bar.txt

The resulting names should be:
Foo.txt
Foo_1.txt
Bar.txt
Bar_1.txt
Bar_2.txt

With “Append incrementing number” I'm getting:
Foo.txt
Foo_001.txt
Bar.txt
Bar_001.txt
Bar_002.txt

How can I achieve that, without running Advanced Renamer a second time to remove the “00”?


08/04-23 11:49
#2 : 08/04-23 12:49
David Lee
David Lee
Posts: 1125
The Collision Rule will always zero-pad an incrementing number to at least 3 digits.

The easiest solution is to automatically reload all the files, when you run the batch, and then remove the zero-padding using a Renumber method.

Otherwise, if you want to avoid the use of a second pass, you will need to create your own Collision Rule using a Script method.

Allocate an object in the Pre batch script, to keep track of duplicate filenames:

var names = {};

Then, in the main script:

name = item.newBasename;
if(names[name]) return name + names[name]++;
else names[name] = 1;


08/04-23 12:49
#3 : 09/04-23 04:59
David Lee
David Lee
Posts: 1125
Reply to #2:

My previous solution will consider identical filenames to be duplicates even if they have different extensions. To fix this, modify the main script as follows:

name = item.newName;
if(names[name]) return item.newBasename + names[name]++;
else names[name] = 1;


09/04-23 04:59
#4 : 12/04-23 10:27
David Tiede
David Tiede
Posts: 4
Reply to #3:

Nice. Thanks for pointing out. I'll use the script then.


12/04-23 10:27
#5 : 18/04-23 17:31
Bart Kestelyn
Bart Kestelyn
Posts: 3
Reply to #1:
You shouldn't want that, as you'll get unreliable sorting dependent on your OS of choice and its ability to differentiate between 1 and 10 (2 & 20, 3 & 30, ...)


18/04-23 17:31
#6 : 19/05-23 15:20
David Tiede
David Tiede
Posts: 4
Reply to #5:
I know. In my case, I don't have more than 10 files in one group.


19/05-23 15:20