Rename folder based on mp3 tag of included files


I have some folders and files like this:

\ 01 - track1.mp3
\ 02 - track1.mp3
\ 03 - track1.mp3
\ cover.jpg

\ 01 - song.mp3
\ 02 - othersong.mp3
\ cover.jpg

I would like to rename these folders, using the {mp3album} tag from the files it contains. All mp3's within a folder are already organized such that they all belong to the same album. That means that the {mp3album} could be extracted from the mp3 file with this name "01 - XXX.mp3"

I would like to end up with this:

albumtitle (CD1)
\ 01 - track1.mp3
\ 02 - track1.mp3
\ 03 - track1.mp3
\ cover.jpg

albumtitle (CD2)
\ 01 - song.mp3
\ 02 - othersong.mp3
\ cover.jpg

In other words:

  • take the {mp3album} tag from the "01- blabla.mp3" file in the folder, call this X
  • take the original folder name, call this Y
  • rename the folder to X (Y)

Can this be done?

A quick hack would be to rename-move one mp3 file into a new folder with the right name and then copy-move the remaining files into that folder and finally move the new folder up in the hierarchy.

Parameters for the Advanced Renamer
Mode: Standard Wildcard Rename
Old name: *
New name: {mp3album} ({parent})\*
Ignore extension: checked

Probably ok if you only have a few albums. For a fully automated one-click solution you'll need a script.

1 Like

Thank you.
Indeed, that works, but I have a lot of those folders.
Also, it creates a new folder underneath the parent folder, rather than renaming the parent folder. It thus wouldn't work inside the actual folder, but only (like you say) when moving the file into a new folder to begin with. I am hoping for a more automated solution. I appreciate your help.


function OnClick(clickData) {
    var cmd = clickData.func.command;
    var tab = clickData.func.sourcetab;
    cmd.deselect = false;
    if (tab.selected_files.count == 0) return;
    var item = tab.selected_files(0);
    if (item.metadata != 'audio') return;
    cmd.RunCommand('Rename FROM="' + item.path + '" TO="' + + ' (' + item.path.filepart + ')"');
Button as XML
<?xml version="1.0"?>
<button backcol="none" display="both" textcol="none">
	<function type="script">
		<instruction>@script JScript</instruction>
		<instruction>function OnClick(clickData) {</instruction>
		<instruction>    var cmd = clickData.func.command;</instruction>
		<instruction>    var tab = clickData.func.sourcetab;</instruction>
		<instruction>    cmd.deselect = false;</instruction>
		<instruction>    if (tab.selected_files.count == 0) return;</instruction>
		<instruction>    var item = tab.selected_files(0);</instruction>
		<instruction>    if (item.metadata != &apos;audio&apos;) return;</instruction>
		<instruction>    cmd.RunCommand(&apos;Rename FROM=&quot;&apos; + item.path + &apos;&quot; TO=&quot;&apos; + + &apos; (&apos; + item.path.filepart + &apos;)&quot;&apos;);</instruction>


Thank you. It works great as a button!
I would prefer to use it as a rename script, but then nothing happens. I must be doing it wrong. I went to the advanced rename pane and then copied the JS code into the script window. I saved it as a preset. However, nothing happens when I apply it. Do I need to set anything else specific in the rename pane?

A rename script would look very different. Why do you want to use one? How would your workflow look like? From what you have written so far I'd recommend you stick with the button. But feel free to elaborate on the task at hand, I might not have fully understood what you want to achieve.

1 Like

Ah, I am sorry. I am reorganizing several TB of files and there are all kinds of issues with how they are currently organized. As I go along, I am putting together a set of rename scripts that can handle the varied issues that I come across with the files and folders. Using presets helps with keeping dopus itself organized, otherwise my toolbar becomes totally cluttered with a few dozen rename buttons. This is why I would prefer to do this that way. I would then select the appropriate folders or files and apply the appropriate preset.
My ideal workflow in this case would be to either select the folders that need renaming or select the files in those folders from a flat tree view. There is enough organization in these files, so that I can do it that way. Either approach would work. But the button is a good start as well!

If you want to select a file and rename its parentfolder while keeping all the other files in it, the button from above is basically your only option. A rename script would be a major pain, if it worked at all. The button should work everywhere, including in collections and in tabs in flatview.

If you want to select folders and rename them based on the mp3 files they contain, a rename script will work well. A big advantage would be the unlimited number of folders that can be renamed at once. And, of course, the preview.

Awesome, renaming folders based on the mp3 files they contain would be tremendously useful. Can you show me how that would be done, in this case?


var fsu = DOpus.FSUtil();

function OnGetNewName(getNewNameData) {
    var item = getNewNameData.item;
    if (!item.is_dir) return false;
    var foundTag = false;
    var folderEnum = fsu.ReadDir(item, 'r'); // recursive
    while (!folderEnum.complete) {
        var folderItem = folderEnum.Next();
        if (folderItem.metadata == 'audio') {
            var newAlbum =;
            foundTag = true;
    return foundTag ? newAlbum + ' (' + getNewNameData.newname + ')' : false;


That works beautifully! Thank you.