Append folder count to file names

Advanced Renamer forum
#1 : 27/12-22 03:56
JonSmith
JonSmith
Posts: 2
I have folders
Folder A, Folder B, Folder C

Each file contains the same files
File1, File2, File3

I would like a folder count, appended to the filename. If it is the first folder, append 1. If it is the second folder. Append 2. Or a serialize function where it only increases count, on folder change.

New files would be
01 File1, 01 File2, 01 File3
02 File1, 02 File2, 02 File3
03 File1, 03 File2, 03 File3

You guys seem VERY responsive in your support. So. Might as well ask


27/12-22 03:56
#2 : 27/12-22 08:51
David Lee
David Lee
Posts: 1125
Try this Script method...

Define variables in the Pre batch script :

var dirName = {};
var dirs = 0;

Then, in the main script:

dir = app.parseTags('<DirName:1>');
if (typeof dirName[dir] == 'undefined') dirName[dir] = ++dirs;
return dirName[dir] + ' ' + item.name;

Finally, add a Renumber method to fix the zero-padding...

Number position: 1
Change to: Relative to existing number
Number difference: 0
Zero padding: Manual
Number length: 2

This will rename all files (any number) in each folder and will work with any folder names. If you want to number the folders in alphabetical order then sort the List by Path.


27/12-22 08:51
#3 : 27/12-22 19:01
JonSmith
JonSmith
Posts: 2
Reply to #2:
Fantastic response, works like a charm.

So.. Is there a way to just have the script output the number appended to the beginning of whatever the filename currently is? So I can make edits to the filename prior to the script itself.


27/12-22 19:01 - edited 27/12-22 19:13
#4 : 27/12-22 19:49
David Lee
David Lee
Posts: 1125
Reply to #3:

Just replace item.name with item.newBasename in the return statement.


27/12-22 19:49