Renumber Several Lists in One Folder?

Advanced Renamer forum
#1 : 04/07-22 23:38
Flying Penguin
Flying Penguin
Posts: 2
So I have one folder with a bunch of files grouped into categories and numbered, like this:

Alpha 01
Alpha 02
Alpha 03
Bravo 01
Bravo 02
Bravo 03
Charlie 01
Charlie 02
Charlie 03

Except that over time I may add or remove files, so they're no longer numbered in sequence, like this:

Alpha 01
Alpha 07
Alpha 08
Bravo 03
Bravo 04
Bravo 06
Charlie 01
Charlie 11
Charlie 74

I'd like to be able to batch rename them to reset all the numbers within each list, while keeping all the files in the same folder. But with the standard New Name or Renumber methods, I don't see any way to reset the count. It'll just number everything in the folder from 1 - 12.

Is there a way to do this?

04/07-22 23:38
#2 : 05/07-22 02:06
David Lee
David Lee
Posts: 981
Use a Script method and create an object in the Pre batch script to keep track of the numbers you have used for each filename.

There is a small complication since you want the new names to be in the same format as the originals. Advanced Renamer renames files one at a time so it will fail if a new name already exists in the same folder. A simple work around is to carry out the renaming in two separate batches. First use a script method to renumber the files but add a new character that will not be used in any filename. Then just remove the unwanted character in a second batch.

First batch - Script method...

In the Pre batch script enter the following code:

var fileNum = {};

Then in the main script window:

if(* (?=\d+$)/)) {
name = name[0];
if(num = fileNum[name]) num++; else num = 1;
fileNum[name] = num;
return name + "#" + ('0' + num).slice(-2);

Run this batch and select the option to add all files.

Then clean up in a second batch using a Remove pattern method to remove the unwanted "#" characters

05/07-22 02:06 - edited 05/07-22 02:08
#3 : 05/07-22 04:32
Flying Penguin
Flying Penguin
Posts: 2
That worked like a charm!


05/07-22 04:32