Add numbering to the files that don't have it

Hello,
I'm trying to do the following:

1- Add numbering in the format 'xxx - ' (I know how to do this).
2- Change the existing numbering (I know how to do this).
3- But I want to make sure the numbering is only added if it doesn't already exist in the file names. I can't figure out how to do this part.

Here's an example of what I want to achieve:


001 - name01.mp3 >>> 002 - name01.mp3
002 - name02.mp3 >>> 003 - name02.mp3
ghjkname03.mp3 >>> 001 - ghjkname03.mp3

Thank you for your attention.

P.S.: I am using version: 3.77
Reply to #1:
Here's how to add numbers only if missing, using version 3.95... (You should upgrade to that at least)

Create a script method with this code:

zAlreadyNumberedRegx = new RegExp (/^\d{3} - /, "i");

if (zAlreadyNumberedRegx.test (item.newBasename) ) {
return item.newBasename;
}
else {
newNumber = 1; // Set per whatever scheme you are using.

paddedNumber = ("000" + newNumber).slice (-3); // Q&D ensure three digits

return paddedNumber + " - " + item.newBasename;
}

If you upgrade to version 4.17, you will have additional ways to approach the problem.
Reply to #2:

Morning, gents, just a thought,

If you just want "a" number at the start, you could do a Replace method:

Replace: ^([^\d])
With: 001 - $1
Reg Expr: checked

If you then wanted to sequence those numbers, a Renumber method would do it (pos 1; Absolute; New number 1; Skip 1; Manual pad; Number len 3). You have a few ordering options by sort.

Cheers!
DF
Reply to #1:
Ah, thank you very much, the script works well with version 4.17. By adding 'renumbered' afterward, it does exactly what I wanted.

It's a shame that 'does not contain' isn't an option in the conditions that can be applied within 'apply to' {if}.