FileModifyDate's format to interact with "-if gt"

Started by vicmarto, August 29, 2019, 11:08:22 PM

Previous topic - Next topic

vicmarto

Hello!

I'm having some problems with my scripting. What I want to do is process a file only if its FileModifyDate is greater another one FileModifyDate's file:


% exiftool -FileModifyDate pic.jpg
    File Modification Date/Time     : 2019:03:07 13:42:40+09:00

% touch temp

% exiftool -TagsFromFile pic.jpg '-FileModifyDate>FileModifyDate' temp
    1 image files updated

% exiftool -FileModifyDate temp
    File Modification Date/Time     : 2019:03:07 13:42:40+09:00

% stat -f %Sm -t "%Y:%m:%d %H:%M:%S" temp
    2019:03:07 13:42:40

% exiftool -o "~/out" '-FileName<%f.$FileTypeExtension' -preserve -if '$FileModifyDate gt '"\"$(stat -f %Sm -t "%Y:%m:%d %H:%M:%S" temp)"\" pic.jpg
    1 image files copied



pic.jpg is copied, but... it's FileModifyDate is not greater than the temp's one! It's the same.


% touch -t 201903071342.41 temp

% exiftool -FileModifyDate temp
    File Modification Date/Time     : 2019:03:07 13:42:41+09:00

% exiftool -FileModifyDate pic.jpg
    File Modification Date/Time     : 2019:03:07 13:42:40+09:00

% exiftool -o "~/out" '-FileName<%f.$FileTypeExtension' -preserve -if '$FileModifyDate gt '"\"$(stat -f %Sm -t "%Y:%m:%d %H:%M:%S" temp)"\" pic.jpg
    1 files failed condition




And, just adding one second to temp, and the if condition fails, as expected.


Please, where is the problem? THANKS!

--
This is using macOS 10.14.6 and exiftool 11.59

StarGeek

You're forgetting the time zone.  gt is a string comparison and when you take into account +09:00, that makes it greater than the "2019:03:07 13:42:40" that you're comparing it to.  So you either need to remove the time zone from the exiftool output or add it to the stat output.

Or do something completely different.  For example, you can instead use ${FileModifyDate;DateFmt("%s")} which will give you epoch seconds value of the File Modify Date.  And I assume you can do the same with stat (don't know, I'm on Windows).  You can then just do a direct comparison or even do a numeric > comparison at that point.
* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).

vicmarto

Ah! The time zone!  ::)

I like your idea of use ${FileModifyDate;DateFmt("%s")}, I'm sure I can modify the stat output to match. Please, how can I see the output of ${FileModifyDate;DateFmt("%s")}?


% exiftool '-${FileModifyDate;DateFmt("%s")}' pic.jpg
    Invalid TAG name: "${FileModifyDate;DateFmt("%s")}"
    Warning: Invalid tag name '${FileModifyDate;DateFmt("%s")}' - pic.jpg



Thanks!

vicmarto

I'm doing some progress  8)


% exiftool -p '${FileModifyDate;DateFmt("%s")}' -FileModifyDate pic.jpg
    1551933760

stat -f %m pic.jpg
    1551933760


vicmarto

#4
It works!!! HAHHHAA


% exiftool -o "~/out" '-FileName<%f.$FileTypeExtension' -preserve -if '${FileModifyDate;DateFmt("%s")} gt '"\"$(stat -f %m temp)"\" pic.jpg
    1 files failed condition

StarGeek

Sorry, I was away from the computer.  But glad to see you found the -p (printFormat) option.
* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).