ExifTool Forum

ExifTool => The "exiftool" Application => Topic started by: c++ on October 20, 2014, 03:39:33 PM

Title: Is it possible to get a tag via -tagsFromFile only if not already set
Post by: c++ on October 20, 2014, 03:39:33 PM
I have a quick question: Is it possible to get a tag via -tagsFromFile only if that tag is not already set? I'd like to do that in a single command line that does other things as well. If I read it right the -if flag would cancel the whole command's execution if false. What I rather seek is preventing to overwrite a specific tag in case of it being already populated.
Title: Re: Is it possible to get a tag via -tagsFromFile only if not already set
Post by: Phil Harvey on October 20, 2014, 07:07:34 PM
You want to conditionally replace an individual tag if it doesn't exist.  This is done like this:

exiftool -TAG-= -TAG=NEWVAL ...

You may use -TAG-=OLDVAL to replace the tag if it had value OLDVAL, but if OLDVAL is omitted then the tag is written only if it didn't exist before.

- Phil

Edit:  Sorry, I neglected to put this in the context of -tagsfromfile.  This is the command to do that:

exiftool -TAG-= -addtagsfromfile @ "-TAG<SOMEOTHERTAG" ...

Note that you must use -addTagsFromFile instead of -tagsFromFile, otherwise the original assignment is superceded.
Title: Re: Is it possible to get a tag via -tagsFromFile only if not already set
Post by: c++ on October 28, 2014, 08:14:18 AM
Thank you very much. That is exactly what I need. Also thanks for pointing out -addTagsFromFile.