Need a script to promote certain folders

I have a number of folders in the following format:

\Music\Artist1_-_Album_Title1\Artist1 - Album Title1
\Music\Artist1_-_Album_Title2\Artist1 - Album Title2
\Music\Artist2_-_Album_Title3\Artist2 - Album Title3
etc.

My current workflow is to open the folder that includes underscores (_) in the name and click a button to execute a script that promotes the lower level folder (without the underscores) and deletes the now empty folder. Unfortunately, even this script is proving to be time consuming because I need to open each folder and then execute the script. It would be much easier if I could select a number of folders and then execute a script that would promote any subfolders found in the selected folders and then delete the selected folders.

So, after selecting the folders above and running the script, I'd have this:

\Music\Artist1 - Album Title1
\Music\Artist1 - Album Title2
\Music\Artist2 - Album Title3

One other thing: Very occasionally, the subfolder will have the same format as the higher level folder (with _) and I need to go another level deeper. I don't expect the script to be able to determine this, but ideally, the script should make sure that any folder it deletes is empty (if it promotes a folder with the same name as a folder at the higher level and then deletes that folder, I have a problem).

Thanks in advance for any help!

Navigate to the top folder (Music) and try the Advanced Rename with this

Mode: Standard
Old name: *
New name: $.\{parent1}\*
Ignore extension: checked
Rename files in selected sub-folders: checked

Thanks, Ixp. That seems to work (though I've only been able to test on some dummy files I created for the purpose). However, after running that rename process, I'm left with a bunch of empty folders. I suppose I can use RED to delete the empty folders, but the fewer manual steps that I need to execute, the better off I'll be.

GetSizes (Ctrl-L) will find empty folder quickly, or use FIND, or Delete with SKIPNOTEMPTY, or run a batch file for /f "delims=" %%d in ('dir /s /b /ad ^| sort /r') do rd "%%d".

Now I've got some parameter definition reading to do! Thanks again.

So I played around with the Advanced Rename suggestion and discovered a problem (that I should have thought to mention in my original post). Many of the folders have subfolders such as \CD1, \CD2, and \Covers. When I use $.\{parent1}\* those subfolders are promoted to the top level instead of staying as subfolders and promoted with their parent. In other words, right now, my results become:

\Artist1 - Album 1
\Artist1 - Album 2
\CD1
\CD2
\Cover

I'd like the results to be:

\Artist1 - Album 1\
\Artist1 - Album 1\CD1
\Artist1 - Album 1\CD2\
\Artist1 - Album 2
\Artist1 - Album 2\Cover

Does that make sense?

Again, thanks in advance for any help.

This will remove the folders beneath Music from the folder structure and leave the rest as is. So CD1 etc. will stay where they are. It will not solve the problem of duplicate folders mentioned in the first post. The preview will help with testing the script.

function OnGetNewName(getNewNameData) {
    var tmpPath = String(getNewNameData.item.path);
    var tmpStem = getNewNameData.newname_stem;
    var tmpExt = getNewNameData.newname_ext;

    DOpus.Output(tmpPath + '\\' + tmpStem + tmpExt + ' --->');

    tmpPath = tmpPath.replace(/(.*\\Music)\\.*?(\\.*)/, '$1$2');

    DOpus.Output(tmpPath + '\\' + tmpStem + tmpExt + '\n');

    return tmpPath + '\\' + tmpStem + tmpExt;
}

32859b.orp (742 Bytes)

Wow. That was fast! Thanks for that. I'll try to play around with it tonight (what is the likelihood that my family will leave me alone two nights in a row?).

I'm sure it's a case of user error (in other words, me), but I can't get the script to do … well, anything. I tried copying and pasting the script above and I tried importing the .orp file. Nothing seems to work. I hate to sound like an idiot, but perhaps I need more detailed instructions on just how to make this all work. Thanks again.

What does your Rename dialog look like when you double-click the imported preset (the one from the .orp file)?

It appears that the problem was definitely user error. I started over last night. Imported the .orp file again … and everything appears to have worked as expected. Not sure why it (or I) had issues the other night. I'll test more thoroughly this weekend (hopefully).

Quick thought: If you are not certain the folder Music is unique within your (entire) folder structure rename it on your drive and in the script to something truly unique to avoid having the regex mess up your tree.

Thanks for the suggestion, Ixp. I just used "Music" as a placeholder in my initial message but checked the script to see if I needed to change that and did so. At least I managed something on my own!

Thanks again for all the help. Used the script extensively this weekend and it saved me loooooooooots of time.