ExifTool Forum

ExifTool => The "exiftool" Application => Topic started by: ericconn on December 18, 2020, 10:59:32 PM

Title: Using -if, what character(s) means a field isn't empty?
Post by: ericconn on December 18, 2020, 10:59:32 PM
I'm trying to return a list of files that have a value in the keyword field, ignoring files with no keywords, for output to CSV. What do I put between slashes to signify a field has a value? Thanks so much.

exiftool -if "$keywords =~ /?/i" -keyword -csv "C:\Scan_Location" -r  "C:\Output.csv"
Title: Re: Using -if, what character(s) means a field isn't empty?
Post by: StarGeek on December 18, 2020, 11:17:24 PM
If the Keywords tag exists and has entries, then you can simply use
-if "$Keywords"

There are two edge cases where this will fail though, but they would be rare.  First is if Keywords exists but only contains one entry which is a empty string.  The second would be if it contains one entry with a value of the number 0.  That is because Perl would regard both of these as False.

Alternatively, you could use
-if "defined $Keywords"
which will only fail if Keywords does not exist.
Title: Re: Using -if, what character(s) means a field isn't empty?
Post by: ericconn on December 19, 2020, 12:53:10 AM
Excellent, thanks so much!