Insert Parent-Directory into Filename

Hi all,

I really have searched and read a lot in this forum but I can´t find the right solution.
I have following data-structure:
---01 - Track a
---02 - Track b
---03 - Track c

Subsequently I want to insert the Artist into the Filename like:
01 - Artist - Track a
02 - Artist - Track b

Therefore I tried following:
-> Actions
-> Replace with regular expression

Regular Expression: ^(\d+ )
Replace matches with: $1\- %_parent_directory%

It nearly works, but instead of the Artist, the string "%_parent_directory%" appears in the filename.
01 - %_parent_directory% - Track a

What have I done wrong ?
How I have to embed the %_parent_directory% into the regular expression that it works correctly ?

There might be involved some Mp3tag specific internally behaviour or some syntax rule for the replacement part of the Regular Expression within an Action 'Replace using Regular Expression', which your expression take not into account.

I would say, building the complete filename from scratch, what means from existing tag-field content resp. from pseudo tag-field content like %_parent_directory%, would be a rather simple way to go.

You have several options to reach your goal.

  • Use an action 'Format value' to format the filename completely new from tag-field content.

  • Use an action 'Format value' to format the filename using the $replace function ...

$replace(%_filename%,' - ',' - '%_parent_directory%' - ')

( ... makes sense when only one hyphen exists in the filename)

  • Use an action 'Format value' to format the filename using the $regexp function ...
$regexp(%_filename%,'^(\d+\s-)(.+?)$','$1 '%_parent_directory%' - $2')

... or ...

$regexp(%_filename%,'^(\d+\s-\s)(.+?)$','$1'%_parent_directory%' - $2')


Hi DetlevD,

thank you for your quick answer.

I´ve tried your suggestions:

- Use an action 'Replace' and replace the string sequence ...
' - ' 
' - '%_parent_directory%' - '

- Use an action 'Format value' to format the filename using the $regexp functiion ...
$regexp(%_FILENAME%,'^(\d+ )(.+?)$','$1 - %_parent_directory% $2')

The first suggestion I tried earlier.
Unfortunately I get on both solutions following result:

01 - %_parent_directory% - Track a

Why "%_parent_directory%" gets ignored ?

Yes, it seems that both actions 'Replace' and 'Replace using Regular Expression' have the same restriction, when the content of a (pseudo-) tag-field should be used in the replacement part.

I have edit my proposal from above to apply an action 'Format value' together with the function $replace resp. $regexp.


DetlevD !

Thank you, thank you, thank you !!!
All your suggestions above are now working. Perfect.

Great Program - Great Forum - Great People !!!