Add a variable for parent directory


I propose a variable be added into Picard for getting the name of the folder in which the song resides

Currently there’s only one (afaik) variable named _dirname, which returns “The name of the directory containing the file at the point of being loaded into Picard.”, but this is incorrect (or atleast the naming isn’t), because what is does is return the full location path of the song’s folder (replaces special symbols with underscores, also).

Example, if a song resides in C:\Temp\Music\Random, the _dirname parameter will return “C__Temp_Music_Random”.

I have a lot of folders named Random for separate songs and I’d writing an if/else rename script. I’d like a variable to get the name of the folder so I wouldn’t have to do _dirname value parsing which might end up faulty :frowning:

Thank you for your input

How are you displaying this? The reason I ask is that in my testing here, the %_dirname% variable actually holds the correct path “C:\CD Rip\Ripped” on my Windows system.

I mean, this is what the “File naming script editor” shows.

And again, it doesn’t show just directory name, but full path, those are 2 different things.

The file naming script will honor the “Windows Compatibility” option settings under File Naming Options regarding replacement of special characters (including the colon and backslash) which is enabled by default on Windows systems. That’s why you’re seeing the character replacement. If you want just the directory portion of the path and not the drive information, simply put $set(_dirname,$substr(%_dirname%,2,)) at the start of your script.

Thank you, but once again, I don’t want either the drive nor the path, I just want the name of the folder that the song is in.

If songs are under C:\Temp\Muzika\Random, then I just want the “Random” part of the path.

That’s why I think a new variable should be introduced just for this.

Also I saw that there’s a ticket system, so maybe I should make a ticket there.

If you just want the final part of the path, that’s actually pretty simple, without the need to add another specific-use variable. Use $set(_last_folder_only,$rsearch(%_dirname%,[^_]*\$)) in your file naming script to create a new %_last_folder_only% variable.