if... if... else

Started by gambling, October 22, 2024, 04:28:37 AM

Previous topic - Next topic

gambling

Hello friends of exiftool.

I need a command with two "if" and the "else" statement.

First IF:
If DateTimeOriginal exists, i want to copy/write it to all other possible dates

Second IF:
If DateTimeOriginal does not exist, but if CreateDate exists, i want to copy/write it to all other possible dates

Else:
If both (DateTimeOriginal and CreateDate) do not exist (meaning both if conditoins do not match), I want to try to read the filename and copy/write the date to all other possible dates


Can i use this one?:
exiftool -r -P
-if "$DateTimeOriginal" "-AllDates<DateTimeOriginal" "-FileModifyDate<DateTimeOriginal" "-FileCreateDate<DateTimeOriginal" -execute
-if "$CreateDate" "-AllDates<CreateDate" "-FileModifyDate<CreateDate" "-FileCreateDate<CreateDate" -execute
"-AllDates<$Filename 00:00:00" "-FileModifyDate<$Filename 00:00:00" "-FileCreateDate<$Filename 00:00:00"
/path/to/files/


Thank you very much for you help !!  :)

Phil Harvey

You don't need to use -if here.  Just do this:

exiftool "-alldates<$filename 00:00:00" "-alldates<createdate" "-alldates<datetimeoriginal" DIR

The rightmost valid argument on the command line takes precedence.

But note that AllDates represents only the 3 common EXIF date/time tags: CreateDate, ModifyDate and DateTimeOriginal, so only these tags will get written.

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

gambling

thank you very much !! That worked  8)  :)

gambling

#3
hello (again...).

is there a way to copy/write a date to multiple other meta data?

Background:
i have A LOT (more then 50k Pictures and Video files). Most of them are clean with right exif dates.
But a lot of them are from some messengers, from internet download, from screenshots, etc...
these files have wrong or even no exif dates,... but some have a filename like IMG-20231012-Whatsapp.jpg or eg. BlaBla_20231012-142348-xyz.jpg

Now I want to take the oldest date of all possible dates and copy/wirte these date in "FileModifyDate" AND the 3 common exif "AllDates".
And if there is no date in the exif data, i will try to read from the filename string (first try with right time, or if there is no time, then use 00:00:00)

4 Expamples:
- File with only CreateDate --> shuld take this CreateDate and copy/write it to "FileModifyDate" and "AllDates"

- File with CreateDate from eg. 2018 but DateTimeOriginal from 2017 --> should copy/wirte the older date (DateTimeOriginal) to to "FileModifyDate" and "AllDates"

- File with no exif date, but name is something like IMG-20200518-BlaBla.jpg --> should copy/write date 20200818 with time 00:00:00 to "FileModifyDate" and "AllDates"

- File with no exif date, but name is (with time) something like IMG-20200518-172048_BlaBla.jpg --> should copy/write date 20200518 with time 17:20:48 to "FileModifyDate" and "AllDates"


I could realise these in different commands i think. But is there a way to to that all with only one single command?

Maybe something like this?
If one of the 3 common EXIF Dates exists, write it to AllDate. If not, take it from Filename with time or with 00:00:00
Same for FileModifyDate

exiftool "-FileModifyDate<$filename 00:00:00" "-FileModifyDate<filename" "-FileModifyDate<modifydate" "-FileModifyDate<createdate" "-FileModifyDate<datetimeoriginal"
"-alldates<$filename 00:00:00" "-alldates<filename"
"-alldates<modifydate" "-alldates<createdate" "-alldates<datetimeoriginal" DIR


Thank you (again!)  :)

Phil Harvey

I don't have time right now for a detailed answer, but reading this thread should provide some help.

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