How to display (composer) if one exists and blank otherwise

I'm trying to use tag to file name where I want (composer) if one exists and blank otherwise but I can't seem to find the correct syntax. Can someone please tell me where to find this?

I thought it would be something like $if(%composer%) but that doesn't work.

Try for the composer part:
[%composer%]
or even
[ - %composer%]

See also the documenation on Format strings:

Naturally, I'm not certain of your particular approach, but I would use something like:

$if(%composer%,%composer%,)

A quick explanation of what this does:

If the COMPOSER field is populated, the value of COMPOSER is exported to the filename; if it isn't populated, no value is exported.

Consider it like an if, then, else type of construct (separated by the commas).

This is how it might be used in context:

$num(%track%,2). %artist% - %title%$if(%composer%,' - '%composer%,)

And the resulting filename would be something like:

01. Meco - Star Wars Theme - Meco Monardo.mp3

Notice the ' - '%composer% in the above string?

The ' - ' was added in that position so that the extraneous dash only appears in the case that COMPOSER is populated.

I trust this is in some way helpful.

Regards.

I highly recommend the solution in post #2 by @ohrenkino as it uses the standard approach built into mp3tag. Any field enclosed within square brackets is only operated if the field exists. No additional if statements or testing is required in this case.

Exactly. No need for $if, just use

$num(%track%,2). %artist% - %title%[ - %composer%]
which results in
05. ABBA - My Mama said - Benny Andersson.mp3
or if no COMPOSER content exists:
05. ABBA - My Mama said.mp3

As the already linked documentation says about [...]

[...] The contents of brackets are displayed only if at least one of the placeholders used inside the brackets has been found.

That is not entirely accurate.
The entire THEN part ' - '%composer% in your $if formula will only be used if the checked COMPOSER field is not empty.
Just a quick note: apostrophes/single quotation marks aren't really necessary in this case.
$if(%composer%, - %composer%,) works too.

That was entirely accurate.

The "THEN" portion will be used if the COMPOSER field is populated (is not empty) and returns data, just as I said.

You only wrote it differently. :wink:

However, using [ - %composer%] in that fashion is certainly cleaner, as you say.

You are right, I should have phrased it differently.

"Not empty" was a bit too casual here and blurred the actual distinction. The condition is not really "not empty" versus "empty" - it is whether the field exists or not.

An empty COMPOSER field is not possible in this context: the field either exists and has a value, or it does not exist at all. So the relevant point is the presence of the field, not whether it is empty.

Both variants - your $if(x,y,z) syntax and the usual [x] check - evaluate whether field X exists.