counting subfolders based on a pattern

Advanced Renamer forum
#1 : 08/12-20 12:54
Posts: 19
Hi guys,

is there any relatively simple way to change a name of a folder in such a way that the new name contains the number of subfolders with specific name pattern?

Eg folder: <main_folder> contains 10 subfolders named <999px> and 15 subfolders named <999vx>, where 9 is a digit.

I want to rename <main_folder> into <main_folder 10px 15vx>


08/12-20 12:54
#2 : 13/12-20 12:04
Posts: 19
Reply to #1:

no any idea?

13/12-20 12:04
#3 : 14/12-20 13:53
David Lee
David Lee
Posts: 1071
Took a lot of thought!

You can do this using scripting. This code will rename one main folder at a time and assumes that the folder contains only -px and -vx files.

It uses a Pre batch script only to count the numbers of px & vx files and identify the root folder then it will rename the root folder.

Drag your "main_folder" into the list and select "Add the folders", "Add subfolders" & "Add root folders".

Leave the Main script blank.

Pre batch script:

var px = 0;
var vx = 0;
var root = -1;
for (j=0; j<app.itemCount; j++){
folder = app.getItem(j);
type =\d*(px|vx)/);
if (type) {
if (type[1] == "px") px++;
else if (type[1] == "vx") vx++;
else root = j;
rootName = app.getItem(root).name;
app.getItem(root).newName = rootName + " " + px + "px " + vx + "vx";

Renaming multiple root folders in one go is possible but will require more complex scripting. You would need to identify the corresponding root folders for each sub-folder, using item.filename - which will return the full path and then maintain separate counts of vx & px for each root folder.

14/12-20 13:53 - edited 14/12-20 14:19
#4 : 15/12-20 13:31
Posts: 19
Reply to #3:
David, thanks a lot!

Although hoped it could be done more simple way :-)

15/12-20 13:31