exiftool output into an array - matching the indexing of the input array

Started by zakamon, October 12, 2020, 08:50:31 PM

Previous topic - Next topic

zakamon

What I would like to do is to start with an array of thousands of jpegs. I'd run those jpegs through exiftool to get another array of datetime strings, and again to get another array of orientations (0, 90, 180, 270). For all three arrays, every array[$n] would refer to the same jpeg,one for the full file path, another for the datetime string, and another for the orientation. Then my script would go on to do other things with those jpegs and that info.

That works on a small set of test jpegs in Bash:
readarray -t jpg_dates < <( exiftool -createdate "${jpgs[@]}" | grep Create | sed 's/^[^:]*://g' | sed -e 's/^[[:space:]]*//' | sed -e 's/\s.*$//' )

However, if a jpeg doesn't have a createdate tag, there is no return to readarray, not blank, not an error message, nada, so once the script hits a no-tag jpeg, the indexes of the arrays no longer match.

I really like how fast exiftool is in extracting the tags, but I'm wondering if I'll have to switch to running exiftool on each jpeg, instead of on a batch, so I can catch these no-tag losers. Can I make this approach work? Is there a way to get a default output, e.g. 'Createdate: 0000:00:00' or whatever? I'm not attached to manipulating the string before it goes into the array as in the above example.

Thanks!

StarGeek

The -f (-ForcePrint) option will force an empty tag to return a dash.  This can be further modified with the use of -api MissingTagValue

You can also skip the sed step of removing leading text by using the -s (short) option (specifically -s3).
"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


zakamon

exiftool -f -s2 -createdate . | grep :

Thank you so much! This returns just one line from each jpeg, either the datetime string, or the '-' indicating no results. Perfect.