Compare date in folder name with DateTimeOriginal

Started by Fulco, October 27, 2017, 04:39:14 AM

Previous topic - Next topic

Fulco

To check if the 8 digits date in the folder name is not equal to the DateTimeOriginal of an image inside that folder I run this command:

exiftool -q -q -if '${Directory=~/(.*\/)(\d{5,8}) \w/ and ${Directory;s/(.*\/)(\d{8}) (.*)/$2/} ne $DateTimeOriginal' -d %Y%m%d -p 'FileName:         $FileName' -p 'Directory:        ${Directory;s/(.*\/)(\d{5,8}) \w(.*)/$2/}' -p 'DateTimeOriginal: $DateTimeOriginal' /Users/Fulco/Pictures/Wildlife\ Netherlands/20170109\ Birds\ \&\ Animals
FileName:         20170108153359-P1020543.RW2
Directory:        20170109
DateTimeOriginal: 20170108


If the folder name contains a 6 digits date I run this command:

exiftool -q -q -if '${Directory=~/(.*\/)(\d{5,8}) \w/ and ${Directory;s/(.*\/)(\d{8}) (.*)/$2/} ne $DateTimeOriginal' -d %y%m%d

Is it possible to combine these two commands into one?


A complicating factor is that some folder names contain more than one serie of digits. For example:

/Users/Fulco/Pictures/Wildlife Netherlands/20170108 Birds & Animals (170106 - 170112 Texel & Vlieland)
/Users/Fulco/Pictures/Wildlife Netherlands/170108 Birds & Animals (170106 - 170112 Texel & Vlieland)

How can I match the last 6 digits of the first 8 digits (red coloured digits first example) and the first 6 digits (red coloured digits second example) and compare these with the DateTimeOriginal in a single command? Is it anyhow possible?

- Fulco

Phil Harvey

How about this?

if '${Directory;s/.*\/(\d{5,8}) \w.*/$1/} eq ${DateTimeOriginal;s/ .*//;tr/://d} or ${Directory;s/.*\/(\d{5,8}) \w.*/$1/} eq ${DateTimeOriginal;s/ .*//;tr/://d;s/..//}'

Here I reformat the date time as YYYYmmdd and yymmdd manually to do the comparisons.

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

Fulco

Thanks for looking into this. Your command works, but the results show only the date from the folder name and the date from the DateTimeOriginal which compare to each other. I'm however looking for results which are not equal. Is it possible to do this in a single execution? If not I will execute the two commands in one line:

exiftool -if '$Directory=~/(.*\/)(\d{6}) \w.*/ and ${Directory;s/.*\/(\d{6}) \w.*/$1/} ne ${DateTimeOriginal;s/ .*//;tr/://d;s/..//}' -Filename -execute -if '$Directory=~/(.*\/)(\d{8}) \w.*/ and ${Directory;s/.*\/(\d{8}) \w.*/$1/} ne ${DateTimeOriginal;s/ .*//;tr/://d}' -FileName -common_args

- Fulco

Phil Harvey

I don't see why you want to do this in two commands.  Just do an "or" of your two conditions.  (Place round brackets around each first to ensure proper order of operations.)

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

Fulco

The "or" is working now in my command. In the meantime I found a more elegant solution:

exiftool -q -q -if '$Directory=~/.*([A-Za-z]+)(\/20|\/)(\d{6}) \w.*/ and ${Directory;s/.*([A-Za-z]+)(\/20|\/)(\d{6}) \w.*/$3/} ne ${DateTimeOriginal;s/ .*//;tr/://d;s/..//}' -p 'FolderName:        ${Directory;s/.*([A-Za-z]+)(\/20|\/)(\d{6} \w.*)/$3/}' -p 'FormattedFileName: ${FileName;s/\d{2}(\d{6})(.*)/$1 $2/}' -p 'DateTimeOriginal:  ${DateTimeOriginal;s/ .*//;tr/://d;s/..//}' -r

Thank you very much for your help!

Phil Harvey

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