ExifTool Forum

ExifTool => Newbies => Topic started by: Clindor on February 26, 2020, 06:07:09 PM

Title: How to organize instructions depending on -if conditions?
Post by: Clindor on February 26, 2020, 06:07:09 PM
So first I would like to apologize if I'm asking a question that possibly has already been asked because this is a very basic question for which I guess some related-topics already exist, but I just couldn't find them. Don't hesitate to redirect me to the proper place if needed.


So here's the thing, I would like to write one super-command to be applied on several folders (coming from my iPhone) containing lots of documents of three possible different File Type : JPEG, PNG, and MOV, all-mixed together, and for which MOST of the Time-related Data (including also a lot of MetaData) have been updated with FALSE values (for unknown reasons but including an OS update).

To make my super-command possible I would need to group my instructions according to the File Type of each File. Which means I would need:
Instruction1, Instruction2, Instruction3 to be applied only when the File Type is JPEG,
Instruction4, Instruction5, Instruction6 to be applied only when the File Type is PNG,
Instruction7, Instruction8, Instruction9 to be applied only when the File Type is MOV.
There is a double reason for that (first and less important, because all the date-related tags, the "date of creation" for instance, don't have the same tag name depending on the File Type, and I hope to limit the minor warning reports in the output to help me focus on the real problems and encountered errors), but second and more importantly: (because these photos and videos were taken and recorded during a long trip) there is a time difference to be considered inside some instructions when it comes to videos, but NOT when it comes to pictures (JPEG files) because those already have their date-related MetaData ajusted to the time they were taken on location. Yet because Photos & Videos shared some same TAG NAMES (I'm speaking of CreateDate & ModifyDate), so I have to make two different instructions using the exact same tag names: "-FileCreateDate<${CreationDate}+02:00" or "-FileCreateDate<${CreationDate}".

So my question is, if I make one big command that looks like this:

ExifTool INSTRUCTION1, INSTRUCTION2, INSTRUCTION3 -if 'FileType="JPEG"'
            INSTRUCTION4, INSTRUCTION5, INSTRUCTION6 -if 'FileType="PNG"'
            INSTRUCTION7, INSTRUCTION8, INSTRUCTION9 -if 'FileType="MOV"'
            DIR1 DIR2 DIR3 DIR4 DIR5 DIR6 DIR7 DIR8


Does it mean that  INSTRUCTION1, INSTRUCTION2, INSTRUCTION3 will be applied ONLY on JPEG files,  INSTRUCTION4, INSTRUCTION5, INSTRUCTION6 only on PNG files, and  INSTRUCTION7, INSTRUCTION8, INSTRUCTION9 only on MOV files ?

Or is it not how it works ?
Title: Re: How to organize instructions depending on -if conditions?
Post by: StarGeek on February 26, 2020, 06:35:56 PM
The if statement applies to the entire command, so you can't use multiple conflicting IFs.  The easiest thing to do would be to use three separate commands.  You can combine them using the -execute option (https://exiftool.org/exiftool_pod.html#execute-NUM) and the -Common_Args option (https://exiftool.org/exiftool_pod.html#common_args), but it will still require exiftool to do a pass for each, so you don't gain too much by doing so.

Using those options, the command would be more like
ExifTool INSTRUCTION1, INSTRUCTION2, INSTRUCTION3 -if 'FileType="JPEG"' -execute
            INSTRUCTION4, INSTRUCTION5, INSTRUCTION6 -if 'FileType="PNG"' -execute
            INSTRUCTION7, INSTRUCTION8, INSTRUCTION9 -if 'FileType="MOV"'
            -common_args DIR1 DIR2 DIR3 DIR4 DIR5 DIR6 DIR7 DIR8

Note that you don't need an execute for the last group of instructions, it's automatically done when it gets to the end of the command.
Title: Re: How to organize instructions depending on -if conditions?
Post by: Clindor on February 26, 2020, 08:10:39 PM
Great answer, thank you!
..and thanks for arranging this command for me  ;)

Quote from: StarGeek on February 26, 2020, 06:35:56 PM
but it will still require exiftool to do a pass for each, so you don't gain too much by doing so.

Do you mean it would take much more time for ExifTool to execute this command (even your re-arranged version of it?) rather than executing the 3 if-commands if they were seperated? Or would it be the same?
Title: Re: How to organize instructions depending on -if conditions?
Post by: StarGeek on February 26, 2020, 09:29:08 PM
Using the -execute option (https://exiftool.org/exiftool_pod.html#execute-NUM) will save a bit of time, but it depends upon the command. What it does is keep exiftool running instead of exiting after each command.  Since exiftool's biggest performance hit is the startup time, it can save time when you are running a dozen commands in sequence.  For example, I have one arg file that would run exiftool 20 separate times if I didn't use execute.  That ended up being a significant amount of time to process files.

In this case, it probably won't save you more than a second or two.  Which is why I said it would be easier to just run three commands.  It adds complexity to the command without giving enough back to make it worth it, IMO.