Renaming with

Advanced Renamer forum
#1 : 01/10-19 01:17
Posts: 2
I would like to know if there is a way to rename files in dir using <DirName:1><Inc Nr:1>, But instead of add 001-001 (example) make it skip to next Avail number? I have a Dir with over 5000 files I delete duplicates at times and I don't want to rename those I keep. Thanks for any help.

01/10-19 01:17
#2 : 05/10-19 19:47
David Lee
David Lee
Posts: 316
I can suggest a solution using the Script method.

You haven't given enough details to provide you with a specific solution so I will define my own simplified problem thus:

1) We assume the maximum number of files = 9999

2) Files that have already been numbered end with a four digit number starting from 0001: eg qwerty-0001, but some numbers are missing due to deletions.

3) New files added to the folder do not end with this pattern .

4) We wish to append a hyphen followed by the smallest available number padded with leading zeroes to each new filename in the list.

The strategy is first to make a table indicating which numbers have already been used.
You must do this in the separate Pre batch script that is run once only before iterating and processing all the filenames in the list.

Then in the main script check each item in the list and if it doesn't already end with the number pattern find the next available number and append it.

ARen can only read filenames from the list so you must import ALL the files in the folder into the list.

To implement copy the following code into the two script windows.
Note that all text following "//" is a comment and will be ignored when the scripts are run.

1) Pre batch script...

var testN = new Array(10000); // Allows numbers up to 9999
for (x = 0; x < 10000; x++) {
testN[x]=0; // Initialize a test array to zero
noFiles = app.getItem(0).filesInDir; // Find total number of files in the folder

for (x = 0; x < noFiles; x++) { // Step though all the filenames in the list
name = app.getItem(x).name;
num = name.match(/\d{4}$/); // Check for a number at the end of the filename
if (num != null) testN[num * 1] = 1; // If a number then set the test array element = 1
var lastN = 1 // Set the starting number = 1

2) Main script:

name = item.newBasename // Get the current filename
if (!/\d{4}$/.test(name)) { // Test if it is a new file
while (testN[lastN] == 1) ++lastN // Find the next unused number
testN[lastN] = 1; // Flag that number as used
name = name + "-" + ("000" +lastN).slice(-4); // Append the number with leading zeroes
return name;

05/10-19 19:47 - edited 06/10-19 09:07
#3 : 13/10-19 20:23
Posts: 2
Reply to #2: Thank you for your Reply.
Is there a simpler script such as.. (Skip if =to ### exist.) Sorry not familiar with scripting.

13/10-19 20:23