Remove part of a subfolder name if it matches parent

Javascript renaming examples. Javascript renaming is supported in version 3 or newer.

Remove part of a subfolder name if it matches parent

Postby Admin » Wed Jun 01, 2016 12:52 am

Take a folder:
with subfolders that all start with ZZ TOP

Want to rename the sub folders into: C:\MUSIC\ZZ TOP\GREATEST HITS
In other words, remove the (ZZ TOP - ) from the beginning of all subfolders, leaving just the album name.
I hope this can be done as I have a music collection with over 400 thousand folders, many named as above creating long file names at the file level.

So remove the initial part of a subfolder name if that matches the parent folder.

This can be done with the following javascript function:

Code: Select all
var path = object('folder');
var subfolders = path.split("\\");
var lastsub = (subfolders.length > 1) ? subfolders[subfolders.length - 2] : "";
newName = name.replace(lastsub, "");
newName = newName.replace(" - ", "");

Use Filter (12) to only select to view Folders and activate Subfolders.

Then select all and apply above function.
Site Admin
Posts: 1496
Joined: Tue Mar 08, 2005 8:39 pm

Return to Javascript Renaming