ExifTool Forum

ExifTool => The "exiftool" Application => Topic started by: Natural6163 on November 24, 2023, 02:13:21 AM

Title: How to hide missing properties?
Post by: Natural6163 on November 24, 2023, 02:13:21 AM
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 ( ).
Title: Re: How to hide missing properties?
Post by: StarGeek on November 24, 2023, 09:31:38 AM
Try this (I haven't tested it)
${Year;$_="(".$_.")"}

No, that's not going to work either.  Let me get back to you on this.
Title: Re: How to hide missing properties?
Post by: StarGeek on November 24, 2023, 11:12:10 AM
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.
Title: Re: How to hide missing properties?
Post by: Natural6163 on November 24, 2023, 09:12:08 PM
It's working now.
What does the expression $_=($_) mean?
Title: Re: How to hide missing properties?
Post by: StarGeek on November 24, 2023, 10:31:28 PM
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.