Topic: File Renaming

I want to rename files as they're saved.  I want to leave them in their original folder, with the filename [artist] - [title].  I also want artists starting with "The" to be converted to a ", The" suffix (e.g.; "The Smashing Pumpkins" to "Smashing Pumpkins, The").  In MusicBrainz Picard I have "Options/Rename files when saving" checked and this in "Name files like this:

$firstalphachar(
   $if(
    $eq($left($lower(%artist%),4),the ),
        $right($upper(%artist%), $sub($len(%artist%),4)),
    $upper(%artist%)
   ))/

$if(
    $eq($left($lower(%artist%),4),the ),
        $right(%artist%, $sub($len(%artist%),4))\, The,
    %artist%
)/

$if2(%artist% - %title%)

It's not working.  Filenames are staying as original.  Also, I am pretty much done tagging.  Is there a way to force-rename all of my files without having to go through the motions of "re-saving" the files?

Re: File Renaming

Your script is only adjusting the artist names in the folder parts of the file naming syntax; not the file name part. if you don't have "move files" enabled; the folder parts of the syntax (anything before the final '/') are essentially ignored.

Also $if2(%artist% - %title%) does nothing - it's the same as %artist% - %title%. Not sure what you were trying to achieve with that.

You probably want something like

$firstalphachar(
   $if(
    $eq($left($lower(%artist%),4),the ),
        $right($upper(%artist%), $sub($len(%artist%),4)),
    $upper(%artist%)
   ))/
$if(
    $eq($left($lower(%artist%),4),the ),
        $right(%artist%, $sub($len(%artist%),4))\, The,
    %artist%
)/
$if(
    $eq($left($lower(%artist%),4),the ),
        $right(%artist%, $sub($len(%artist%),4))\, The,
    %artist%
) - %title%

or in a tidier fashion:

$set(normartist,
    $if(
        $eq($left($lower(%artist%),4),the ),
        $right(%artist%, $sub($len(%artist%),4))\, The,
        %artist%
    )
)
$firstalphachar($upper(%normartist%))/%normartist%/%normartist% - %title%

You need to re-save files in order to rename them - but don't need to manually re-match them or anything. They can be saved/renamed from either the left or right hand panes.

Re: File Renaming

Thanks for the help.  I'm not a coder so I have a hard time parsing the syntax.  I do know that something's wrong though.  I used the shorter code option.  Here are some sample filenames:

k Sinatra, The - The Very Thought Of You.mp3

reen, The - Let's Stay Together (Long Version).wma

It's truncating the artist first name (Frank Sinatra and Al Green) and appending ",The" even if there was no "The" prefix.

Re: File Renaming

Right, yes - sorry, I just assumed you had tested that bit. The problem is due to the whitespace in the $if, $eq etc (which is a bit weird... will look further later at whether we need to change Picard code to avoid the strange behaviour).

This will work:

$set(normartist,$if($eq($lower($left(%artist%,4)),the ),$right(%artist%, $sub($len(%artist%),4))\, The,%artist%))
$firstalphachar($upper(%normartist%))/%normartist%/%normartist% - %title%

Re: File Renaming

Or use the $swapprefix plugin from http://musicbrainz.org/doc/MusicBrainz_Picard/Plugins

$set(normartist, $swapprefix(%artist%,The,A))
$firstalphachar($upper(%normartist%))/%normartist%/%normartist% - %title%

You can set as many prefixes as you want. The above will move both "The " and "A " to the end, but you can just use "The" or anything else.