Add and increment

Advanced Renamer forum
#1 : 02/02-21 16:11
Alex
Alex
Posts: 1
Hi,

I have files like this:

1.jpg
1_1.jpg
1_2.jpg

2.jpg
2_1.jpg

It needs to be:
1_1.jpg
1_2.jpg
1_3.jpg

2_1.jpg
2_2.jpg

In other words the filename that has no underscore needs to have _1 added to it
Filenames with pre-existed underscores need to have number after underscore incremented by one

Any help will be appreciated.
Thanks!


02/02-21 16:11
#2 : 02/02-21 22:54
David Lee
David Lee
Posts: 1125
Try a script method with the following code:

match = item.name.match(/(.*_)([0-9]+)$/);
if (match) {
return match[1] + (match[2]*1 + 1);
} else {
return item.name + "_1";
}

To avoid "collisions", make sure that the filenames in the List are in DESCENDING order - ie higher numbers at the top.
(Clicking on the "Filename" header will toggle between ascending and descending order).




02/02-21 22:54