News:

2023-03-15 Major improvements to the new Geolocation feature

Main Menu

-if for date/time

Started by justmike, August 16, 2016, 11:20:26 AM

Previous topic - Next topic

justmike

Is it possible to use the current date and time in an argument? If I would like to find filed created in the last 24 hours, for example.

Phil Harvey

Yes (using the Extra "Now" tag), but the trick is adjusting this by 24 hours before the comparison:

exiftool -filename -if "$createdate gt ${now;ShiftTime($_,-24)}" DIR

- 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 ($).

justmike

I received a "bad substitution" error. Regarding the shiftTime... all I want to do is search. Will that actually shift it?
exiftool -filename -if  "$createdate gt ${now;ShiftTime($_,-24)}" DIR >/Testing2.csv

justmike

"bash: $createdate gt ${now;ShiftTime($_,-24)}: bad substitution"

justmike

Sorry—it was a single quote issue. exiftool -filename -if -r '$createdate gt ${now;ShiftTime($_,-24)}' DIR >/DIR/Testing2.csv

Received File not found: $createdate gt ${now;ShiftTime($_,-24)}

Do I need the directory in front of the command in this instance?

Phil Harvey

The -if condition must come immediately after the -if option.   The -r in your command is now being interpreted as the condition, so it must be moved elsewhere in the command line.  Try this:

exiftool -createdate -r -csv -if '$createdate gt ${now;ShiftTime($_,-24)}' DIR >/DIR/Testing2.csv

Note that I am using the CreateDate tag here, which is the creation date from the EXIF metadata.  I don't know if this is what you had in mind.

- 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 ($).

justmike

I did notice that, and nothing meets the conditions, even when I change the hours to accommodate the time when the original was made. I adjusted the code to use the FileModifyDate, and again, nothing meets the conditions. 

exiftool -FileModifyDate -r -csv -if '$FileModifyDate gt ${now(-24)}' DIR >DIR/Testing2.csv

I get: 11 directories scanned
    8 files failed condition
    0 image files read


I know one file meets the conditions, because its create date modify date is: 2016:08:15 13:17:41-05:00

Phil Harvey

Quote from: justmike on August 16, 2016, 12:34:02 PM
exiftool -FileModifyDate -r -csv -if '$FileModifyDate gt ${now(-24)}' DIR >DIR/Testing2.csv

You broke your -if condition somehow -- the ShiftTime call is missing.  See my first example.

- 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 ($).

justmike

exiftool -filename -FileModifyDate -r -csv -if '$FileModifyDate gt ${now;ShiftTime($_,-24)}' DIR >DIR/Testing2.csv

Nothing... 11 directories scanned
    8 files failed condition
    0 image files read

Phil Harvey

What version of ExifTool are you using?  This works for me with the current version.

- 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 ($).

justmike

Version 10.25, now, and it worked... Thank you!

justmike

It works in the example you gave, but when I add other things to it, I get all the items listed, not just the ones modified in the previous 24 hours. In this case, it was over 60,000 images. Only 900 or so were changed, and I wanted to list those, not the others. Do I need to include an -if statement for each of the elements I am trying list? I guess the best way to say it is, I do not want a filepath, etc, if the modify date is not in the last 24... Is that somehow outside of the conditional statement?
exiftool -r -filepath -FileModifyDate  -originaldocumentid -documentid -subject -csv -if'$FileModifyDate gt ${now;ShiftTime($_,-24)}' DIR >DIR/File.csv

Phil Harvey

You need a space after the -if option.

(watch those details!)

- 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 ($).

justmike

 :o Man I really thought it was going to be more complicated than that... I am running it now—takes about 50 minutes, usually, to go through all the files. I will update—thanks!

justmike

Fantastic—that got it. Thank you very much!!