Would like to rename folders now

Hello,

I’m currently using the following script to rename my files:

$if($and(%albumartist%,%tracknumber%),$num(%tracknumber%,2) ,)- %title%
$set(albumartist,$rreplace(%albumartist%,\s+feat\…*,))

I would like to add folder renaming now. I would like the format to be:

ARTIST - (YEAR) ALBUM NAME

Can anyone help me with adding this folder renaming task to my current script?

Thank you,
Jaimie

For the folder renaming use:

$if2(%albumartist%,%artist%) - \($left(%date%,4)\) %album%

To combine this with the script for your file name you use / to separate the folder, so the script becomes:

$if2(%albumartist%,%artist%) - \($left(%date%,4)\) %album%/$if($and(%albumartist%,%tracknumber%),$num(%tracknumber%,2) ,)- %title%

Not sure about the second line of your script, it currently has no effect as it just sets the variable albumartist, but after it has been already used.

$set(albumartist,$rreplace(%albumartist%,\s+feat\…*,))

If you actually want this to remove the featuring from your file names place this line at the beginning of the script.

2 Likes

Amazing! Thank you! I don’t have a clue how to write scripts, I’ve basically just been cutting and pasting various scripts Ive found to try and get what I want to work.

It’s actually not that hard, just don’t get intimidated by all the $, % and parantheses :smiley: If you can write down a pattern like “ARTIST - (YEAR) ALBUM NAME” you can quite easily translate this to the proper script.

First have a look at what we need, see the available tags at https://picard-docs.musicbrainz.org/en/variables/tags_basic.html. We want the “ARTIST”, available tag for this could be albumartist or artist. This should be the name for an album folder, so albumartist sounds what we need. To get the actual value for a tag enclose its name in percentage signs. So let’s start:

%albumartist%

Now we want the “YEAR”. There is no year tag, but date. Let’s use this for now. If we want to add extra text like the “-” just write it down. We need to be careful with the parentheses, because those are special variables in scripting. We need to prefix them with a backslash. Let’s add this all:

%albumartist% - \(%date%\)

Now finally the “ALBUM NAME”, that’s simple, just use album:

%albumartist% - \(%date%\) %album%

Looks nearly as what you had in your original question :smiley: It’s not perfect yet: We get a full date instead of year. Also if you tag existing files they sometimes might not have the albumartist set, just artist.

Let’s fix the artist first. We can fallback to using artist if albumartist is not available by using

$if2(%albumartist%,%artist%) - \(%date%\) %album%

$if2 uses the first value that is not empty, so if albumartist is empty it uses artist instead.

For the date the dates from MusicBrainz are always formatted as YYYY-MM-DD, e.g. 2020-11-02 for today. So let’s get just the first 4 characters with the $left function:

$if2(%albumartist%,%artist%) - \($left(%date%,4)\) %album%

Let’s do one step more, which I did not have in my original answer. What happens if there is no date? Sometimes MusicBrainz does not have the release date of an album set as it is not known yet. Would be great to omit the entire date with the parentheses in this case. Let’s use the $if function to check whether date is set:

$if2(%albumartist%,%artist%) - $if(%date%,\($left(%date%,4)\) )%album%
8 Likes

@outsidecontext, terrific explanation! I hope you don’t mind, but I’ve edited it slightly and added it as the first item in a new “Tutorials” section of the Picard User Guide.

5 Likes