Specify a condition to be evaluated before processing each *FILE*.
*EXPR* is a
Perl-like logic expression containing
tag names prefixed by "$" symbols. It is evaluated with the tags from each *FILE* in turn, and the file is processed only if the expression returns
true. Unlike Perl variable names, tag names are not case sensitive and may contain a hyphen. As well,
tag names may have a leading group names separated by colons, and/or a
trailing "#" character to disable print conversion. The expression $GROUP:all evaluates to 1 if any tag exists in the specified "GROUP", or 0 otherwise (see note 2 below). When multiple -if options are used, all conditions must be satisfied to process the file. Returns an exit status of 1 if all files fail the condition. Below are a few examples:
Quote: |
# extract shutterspeed from all Canon images in a directory
exiftool -shutterspeed -if "$make eq 'Canon'" dir
# add one hour to all images created on or after Apr. 2, 2006
exiftool -alldates+=1 -if "$CreateDate ge '2006:04:02'" dir
# set EXIF ISO value if possible, unless it is set already
exiftool "-exif:iso<iso" -if "not $exif:iso" dir
# find images containing a specific keyword (case insensitive)
exiftool -if "$keywords =~ /harvey/i" -filename dir |
Notes:
1) The -n and -b options also apply to tags used in *EXPR*.
2) Some binary data blocks are not extracted unless specified explicitly. These tags are not available for use in the -if condition unless they are also specified on the command line. The alternative is to use the $GROUP:all syntax. (eg. Use $exif:all instead of $exif in *EXPR* to test for the existence of EXIF tags.)
3) Tags in the string are interpolated the same way as with -p before the expression is evaluated. In this interpolation, $/ is converted to a newline and $$ represents a single "$" symbol (so
Perl variables, if used, require a double "$").
4) The condition may only test tags from the file being processed.
To process one file based on tags from another, two steps are required. For example, to process XMP sidecar files in directory "DIR" based on tags from the associated NEF:
Code: |
exiftool -if EXPR -p '$directory/$filename' -ext nef DIR > nef.txt
exiftool -@ nef.txt -srcfile %d%f.xmp ... |
5) The -a option has no effect on the evaluation of the expression, and the values of duplicate tags are accessible only by specifying a group name (such as a family 4 instance number, eg. $Copy1:TAG, $Copy2:TAG, etc).