Naming script - square brackets?

Hi folks. Here’s a script that includes the 4 digit year at the front of an album name, for chronological sorting at the folder level. I’m wondering if the script can be modified to output square brackets around the date, rather than round?

The script:

$if2(%albumartist%,%artist%)/ $if(%originaldate%, ($left(%originaldate%,4)),%originaldate%) $if($ne(%albumartist%,),%album%)/$if($gt(%totaldiscs%,1),%discnumber%)$num(%tracknumber%,2) - %title%

The current output:

The Beatles/(1965) Help!/07 - Ticket to Ride.mp3

I can of course batch rename after the fact to replace ( ) with [ ], but thought I’d ask if Picard can do it. I’ve stumbled through some attempts and not gotten it yet.

I assume it is change the outer brackets to squares here:

$if2(%albumartist%,%artist%)/ $if(%originaldate%, [$left(%originaldate%,4)],%originaldate%) $if($ne(%albumartist%,),%album%)/$if($gt(%totaldiscs%,1),%discnumber%)$num(%tracknumber%,2) - %title%

As that is the bit getting the year. This is untested though…

I am confused by the original script as you supplied above. I thought you needed “escape” special characters like () to make them appear in the file name. I would assume original script would have have slashes in front of those brackets I took out - ($left(%originaldate%,4))

Okay… thought so. Now tested. Your original script corrupted when being pasted onto the forum page. Should use the ~~~ thing for scripts, not quote them as forum breaks it as it gets confused by \ character

So using the scripting quote to be clearer, this is now tested:

Take out this

\($left(%originaldate%,4)\)

And replace with this:

[$left(%originaldate%,4)]

Gives you a full script of:

$if2(%albumartist%,%artist%)/ $if(%originaldate%, [$left(%originaldate%,4)],%originaldate%) $if($ne(%albumartist%,),%album%)/$if($gt(%totaldiscs%,1),%discnumber%)$num(%tracknumber%,2) - %title%

As that is my first ever file rename \ moving script it still needs testing. :grinning:

Also I think the script can be simplified a bit by just using $if(%originaldate%,[$left(%originaldate%,4)] ) instead of $if(%originaldate%, [$left(%originaldate%,4)],%originaldate%):

$if2(%albumartist%,%artist%)/
$if(%originaldate%,[$left(%originaldate%,4)] )$if($ne(%albumartist%,),%album%)/
$if($gt(%totaldiscs%,1),%discnumber%)$num(%tracknumber%,2) - %title%
1 Like

I didn’t notice the script got tweaked when pasted in thanks. Yes it seems I have to take out the round bracket and the slash together.

I’ll compare that to the original, thanks.

Can you explain why that one element you removed was unnecessary?

For a bit of background on this, I’ve just learned that Plex ignores text in square brackets (like commenting out something in code).

So my idea in getting this alternate square bracket script is to see if Plex will ignore the year display-wise, presenting my albums with the album title only, while outside Plex at the folder level I still get the years for chronological sorting.

It might not matter, but figured it was a simple thing to test.

In this original script:

$if(%originaldate%,[$left(%originaldate%,4)],%originaldate%)

The $if checks whether the first parameter, %originaldate% is not empty. If it is not emptythen it outputs the second parameter, which is [$left(%originaldate%,4)]. But if it is empty it outputs the third parameter, which in this case is %originaldate%. But in this case it is just empty, nothing to output.

The third parameter is optional, hence this is the same:

$if(%originaldate%,[$left(%originaldate%,4)])

I also tweaked a bit the handling of the spaces. In the end it works kind of the same in this specific case, but how I did it is more logical.

Simplifying a bit the original was like this:

$if(%originaldate%, [$left(%originaldate%,4)]) %album%

So this would add a the originaldate, if set, with a leading space character. Also between the date and %album% is another space always present, even if date is empty. It works because the extra spaces end up at the beginning of the folder name, and whitespace at the start or end of folder and file names gets trimmed.

But anyway, I changed it to this:

$if(%originaldate%,[$left(%originaldate%,4)] )%album%

No extra space in front of the date, and the space after the date only gets added if there is actually a date.

1 Like

It happens any time you try and type a \ for the same reason the \ is needed in front of the (. It has special meaning in the forum page and always needs to be typed twice to appear.

Every time I type \ I have to type two of them.

If you put ~~~ on the line before your script. And again on the line after the script then not only does it paste correctly, but it gets all the funky colours to make it more readable.

thanks. funky test. this is the simplified, square bracket script.

ok that seems to work :slight_smile:

$if2(%albumartist%,%artist%)/

$if(%originaldate%,[$left(%originaldate%,4)] )$if($ne(%albumartist%,),%album%)/

$if($gt(%totaldiscs%,1),%discnumber%)$num(%tracknumber%,2) - %title%
2 Likes