Author Topic: Conditional modification within one command possible?  (Read 3026 times)

icom

  • Jr. Member
  • **
  • Posts: 14
Conditional modification within one command possible?
« on: December 07, 2012, 11:06:07 AM »
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

  • ExifTool Author
  • Administrator
  • ExifTool Freak
  • *****
  • Posts: 19109
    • ExifTool Home Page
Re: Conditional modification within one command possible?
« Reply #1 on: December 07, 2012, 11:12:20 AM »
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, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

icom

  • Jr. Member
  • **
  • Posts: 14
Re: Conditional modification within one command possible?
« Reply #2 on: December 07, 2012, 11:41:16 AM »
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

  • ExifTool Author
  • Administrator
  • ExifTool Freak
  • *****
  • Posts: 19109
    • ExifTool Home Page
Re: Conditional modification within one command possible?
« Reply #3 on: December 07, 2012, 11:54:02 AM »
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, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

icom

  • Jr. Member
  • **
  • Posts: 14
Re: Conditional modification within one command possible?
« Reply #4 on: December 07, 2012, 03:19:41 PM »
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