Extract text before ',' in file naming script?

I have a simple file naming script:
$if2(%composer%,%artist%) - %album%/$num(%tracknumber%,2)_%title%

However, this gives me the entire composer value as in ‘Bach, Johann Sebastian’. I would like to just get the last name, i.e. everything before the ‘,’.

I have tried asking ChatGTP but it just gives me code that does not work.

How can I augment the $if2 function to only return the composer lastname if composer tag is present?

1 Like

First thought would be using $rreplace to get rid of what’s after the comma:


But this would only keep the last name of the first composer/artist. In this way, the solution for a list of artists becomes much more complicated. Only to get the last name of the last composer requires two substitutions.

I had no success so far. Maybe someone else has a better idea.

Hi, thanks for chiming in.
Your suggestion makes me realise I may need to clarify one thing so we don’t talk past each other. I am using the composersort “notation” in my composer tag.

So my composer tags read: lastname, firstname

I will try your suggestion as I could probably live with just having the first composer in the directory path. Thanks!

But of course, if anyone wants to come in on how to manage several composers that is of course welcome.


1 Like