Setting multiple date values from whatever is available

Started by grant, June 30, 2022, 04:46:11 AM

Previous topic - Next topic

grant

I'd like to set FileCreateDate and FileModifyDate from CreateDate and ModifyDate, respectively. However, if those sources aren't available, I'd like to parse the filename for the date info AND ALSO add the missing exif dates. I don't think this is possible in a single execution, so my current thinking is as follows:

1. exiftool -if 'not $CreateDate' '-CreateDate<filename' -r .
2. exiftool -if 'not $ModifyDate' '-ModifyDate<CreateDate' -r .
3. exiftool '-FileCreateDate<CreateDate' '-FileModifyDate<ModifyDate' -r .

That seems to accomplish what I expect with the few test jpg files I've tried it on (save for some timezone offset weirdness). My questions...

1. Is this the best approach?
2. Will this run into any obvious trouble with common media filetypes?
3. Any other advice?

StarGeek

It will still require a separate command to write to the file system time stamps, because you can't write a tag and then use that to copy to another tag, but the first two can be combined by using the -wm (-writeMode) option and note #1 under the -TAG[+-^]=[VALUE] option

exiftool -wm cg '-CreateDate<filename' '-ModifyDate<filename' '-ModifyDate<CreateDate' -r .

Using -wm cg, exiftool will only create new tags, not overwrite existing ones.  The above logic is as follows
If CreateDate doesn't exist, copy from filename, step 1 of your sequence
If ModifyDate doesn't exist, copy from CreateDate if it exists (your step two), otherwise, copy from filename, which would be same as copying '-CreateDate<filename' followed by '-ModifyDate<CreateDate'
* 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).

grant

That looks pretty good, but my understanding is that my if-checks cover the cases where the exif dates are set blank or to zero values. I don't know if that's right or even how common the situation is.

Thanks for your help!

StarGeek

EXIF timestamps are extremely unlikely to be set to empty (0 length) or to just a zero.  Exiftool is about the only tool that will allow you to do this.  Just about every other program is going to force the setting of all 14 digits.

Technically, according to the EXIF specs, if you don't know the exact value of part of the tag, you can set it to blanks.  But that is still not going to be an empty tag and would bypass your -if option, as well as my -wm option anyway.

As an example, if all you knew was the year and month, then the EXIF spec would allow for a value of >2022:01:     :  :  <, with spaces in place of the day, hour, minute, and second.  But again, exiftool is about the only program that will allow you to do this.
* 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).