Exporting - RegEx Folder Question

Hello all. I was hoping to get some help with a regex question. When I do an export action and use %_folderpath%, I get:

F:\music\Blues\Albert King\1967-Born Under a Bad Sign\
explained:
DRIVE:\notImportant\Genre\Artist\AlbumYear-AlbumName\

What I am trying to get, is the Artist folder name from that string above.

So, something like $right(%_folderpath%, -2), that should produce just \Albert King
I just don't know how to traverse the directory, starting from the right, back 2 levels

Also, I can't use the %artist%, because windows machines don't allow /?*"<>|: in directory names; but those characters might be in my Artist Name :slight_smile:

Thanks!
Drew

In this case you will be lucky with %_parent_directory% which results to folder %artist%.

DD.20100205.2310.CET

Well, I need to get all 3 folder levels, so %_parent_directory% won't work for me either.

So, I need regex for:

$right(%_folderpath%, -3)
desired result: \Blues\

$right(%_folderpath%, -2)
desired result: \Albert King\

$right(%_folderpath%, -1)
desired result: \1967-Born Under a Bad Sign\

those regex's are not right, just trying to give you an idea of what i'm trying to do :slight_smile:

Just to make it sure:
Your original question was intended to get the parent directory only.
This was already answered.

Now we try to solve the extended version of your problem.

For the track's directory and the parent directory exist system placeholders:
%_DIRECTORY% and %_PARENT_DIRECTORY%

To get folder names from the folderpath higher up than the parent directory you can use the Mp3tag scripting functions to split the folderpath into it's folder elements. As always there are several possibilities to write fitting code.

Here is one proposal using regular expression function.

%_FOLDERPATH% = "Z:\A4\B3\C2\D1\"

Up 1 level : $regexp(%_FOLDERPATH%,'^(.+?\\\\)*(.+?)\\\\$','$2')            ==> "D1"
Up 2 levels: $regexp(%_FOLDERPATH%,'^(.+?\\\\)*(.+?)\\\\.+?\\\\$','$2')       ==> "C2"
Up 3 levels: $regexp(%_FOLDERPATH%,'^(.+?\\\\)*(.+?)\\\\.+?\\\\.+?\\\\$','$2')  ==> "B3"

DD.20100206.0100.CET

Another version:

Up 1 level : $regexp(%_FOLDERPATH%,'^(?:.+?\\\\)*(.+?)\\\\$','$1')                 ==> "D1"
Up 2 levels: $regexp(%_FOLDERPATH%,'^(?:.+?\\\\)*(.+?)\\\\.+?\\\\$','$1')            ==> "C2"
Up 3 levels: $regexp(%_FOLDERPATH%,'^(?:.+?\\\\)*(.+?)\\\\.+?\\\\.+?\\\\$','$1')       ==> "B3"
Up 4 levels: $regexp(%_FOLDERPATH%,'^(?:.+?\\\\)*(.+?)\\\\.+?\\\\.+?\\\\.+?\\\\$','$1')  ==> "A4"

DD.20100206.0114.CET

Another version:

Up 1 level : $regexp(%_folderpath%,'^(?:.+?\\\\)*(.+?)\\\\(?:(.+?)\\\\){0}$','$1') ==> "D1"

Up 2 levels: $regexp(%_folderpath%,'^(?:.+?\\)(.+?)\\(?:(.+?)\\){1}$','$1') ==> "C2"
Up 3 levels: $regexp(%_folderpath%,'^(?:.+?\\)(.+?)\\(?:(.+?)\\){2}$','$1') ==> "B3"
Up 4 levels: $regexp(%_folderpath%,'^(?:.+?\\)*(.+?)\\(?:(.+?)\\){3}$','$1') ==> "A4"

DD.2011114.1605.CET

You are correct, sorry that I didn't explain it well enough. You have solved my question, thank you very much DetlevD! :smiley: