Conditional modification within one command possible?

Started by icom, December 07, 2012, 11:06:07 AM

Previous topic - Next topic

icom

Hello community,

I was wondering whether it would be possible to have different tag operations executed by a single command line, depending on a certain condition. More clearly:

I want to run exiftool on a set of files, and for each file e.g. modify a certain tag, let's say -comment="New Picture". This shall apply to all files of the set.
Additionally, for some files of the set, e.g. for all files with a filename starting with "DSC", a (new) tag "author" should be set -author="icom".

Of course this could be done by selecting two different sets of files and running exiftool twice. But my idea was, to do this with a single command using the -if EXPR option. While it worked quite well when the condition was true, with the condition being false the files weren't modified at all. Did I do something wrong, or is it not possible to do this in a single command? That's now my impression while reading the documentation ...

Thanks for any help, icom

Phil Harvey

The -if condition is all-or-nothing.

There is no easy way to do what you want without using separate commands.

But if it helps, you can combine 2 commands into a single command line:

exiftool -comment="new Picture" -execute -author="icom" -if EXPR -common_args DIR

This avoids the overhead of loading ExifTool twice, but the files will still get processed twice.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

icom

Hi Phil,

thanks for your prompt reply. The -execute option worked, but I had to add the DIR also before -execute, i.e.

exiftool -comment="new Picture" DIR -execute -author="icom" -if EXPR -common_args DIR

Also options like -overwrite_original have to be given twice. However, the result is what I wanted. Thanks.

icom

Phil Harvey

Everything after the -common_args option applies to all commands.  So in the command you gave, DIR applies twice to the first command, and once to the 2nd, so you are processing these files 3 times.  The same applies to -overwrite_original, which you only need to specify once if it appears after -common_args.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

icom

Oh sorry, that was my misunderstanding - I didn't realize -common_args being an exiftool option, but thought it to be an example; that of course makes it easier again - thank you!

icom