How to hide missing properties?

Started by Natural6163, November 24, 2023, 02:13:21 AM

Previous topic - Next topic

Natural6163

I use
exiftool '-directory<${Artist}/${Album}(${Year})' '-filename<${Artist} - ${Title}.%E' -ext mp3 -r . to organize my MP3 files. If the Year field in the MP3 metadata is empty, how can I prevent the folder from displaying parentheses, like this: Album ( ).

StarGeek

Try this (I haven't tested it)
${Year;$_="(".$_.")"}

No, that's not going to work either.  Let me get back to you on this.
"It didn't work" isn't helpful. What was the exact command used and the output.
Read FAQ #3 and use that cmd
Please use the Code button for exiftool output

Please include your OS/Exiftool version/filetype

StarGeek

Ok, try this
${Year;$_=($_)?"(".$_.")":""}

I still haven't tested it because I can't find a MP3 that has a blank year but has the other tags filled.  I also haven't dealt with MP3 data in years, so I don't have a program to edit it atm.
"It didn't work" isn't helpful. What was the exact command used and the output.
Read FAQ #3 and use that cmd
Please use the Code button for exiftool output

Please include your OS/Exiftool version/filetype

Natural6163

It's working now.
What does the expression $_=($_) mean?

StarGeek

It is more than just $_=($_).  The whole thing is a single operation

$_ is what is called the default variable in Perl.  In the context of exiftool, it holds the value of the tag.

Then the rest of the line is the Perl conditional operator.  It's a short hand way of a IF...THEN...ELSE block.

First ($_). This checks to see if the default variable is TRUE.  It it doesn't exist, is 0, or is a zero length string, it evaluates to false.  Anything else is true.

Then there is the question mark. This is where the branching occurs. The first value after the question mark is what is returned if True.  The value after the colon is returned if False.

It breaks down like this.  If there is a value in the default variable (that isn't 0 or '') then the tag is set to the original value plus parenthesis on both sides.  Otherwise, it is set to '', a zero length string.
"It didn't work" isn't helpful. What was the exact command used and the output.
Read FAQ #3 and use that cmd
Please use the Code button for exiftool output

Please include your OS/Exiftool version/filetype