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
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"