Add sequential number only to checked files

Advanced Renamer forum
#1 : 19/04-19 11:51
Kostas
Kostas
Posts: 1
Hello,

Is there any way to apply a method for sequential numbering to a list BUT only for the checked files?

What I mean is for example that I have 6 files:

file1
file2
file3
file4
file5
file6

and I want to be renamed as

001-file1
file2
002-file3
file4
003-file5
file6

I have to order them before applying the new file if I want to have these numbers. Otherwise they will be renamed as:

001-file1
file2
003-file3
file4
005-file5
file6

which I don't want to.

Imagine that there are a lot more than 6 files, which is a bit painful to order or delete them.
Can I do what I like to do?\

Thanks!


19/04-19 11:51
#2 : 19/04-19 15:38
David Lee
David Lee
Posts: 1125
You can use a script.

If your files are in the correct order in the list (ie file1 to file 6) then it's a simple matter to generate a prefix from the index for the even index-number files (even-numbered because index numbers run from zero):

var prefix = "";
if (!(index % 2)) {
prefix = index/2 +1;
prefix = ("000" + prefix).slice(-3) + "-";
}
return prefix + item.newBasename;


If the files can be in any order then it will be a bit more complex and you can use the match method with a Regular Expression to derive the prefix from the number in the filename for the odd-numbered files:

var prefix = "";
file_num = parseInt((item.name).match(/\d+$/));
prefix = "";
if ((file_num % 2)) {
prefix = (file_num+1)/2;
prefix = ("000" + prefix).slice(-3) + "-";
}
return prefix + item.newBasename;

This, of course assumes that your filenames end with sequential numbers, as in your example. If not then you will have to use the first script.


19/04-19 15:38 - edited 20/04-19 23:34