Mark files with missing DateTimeOriginal field

Started by ULSWK, February 16, 2015, 01:04:14 PM

Previous topic - Next topic

ULSWK

Hi,
I found some posts regarding this problem, but they won't work for my problem ( or maybe I didn't understood how to change the code..)

I'd like to add a keyword called "ADDDATETIMEORG" to all of my files which doesn't contain the field 'datetimeoriginal' or have this field empty.

I tried this:
exiftool -r -Overwrite_Original -Keywords+=AddDateTimeOrig -if "not defined $DateTimeOriginal" D:\Path\*.*

exiftool answered that no file fits to my 'if', but there are definitefly files without that tag.
What is wrong ??


StarGeek

One thing I notice is that you are using the Recurse option (-r) but you are giving it a collection of files ("D:\Path\*.*", in other words, all files in the directory D:\Path\ that have a dot in them).  The Recurse option requires a directory as the target.  Try just using D:\Path\ .

* 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).

ULSWK

OK, I understood, but correcting this that doesn't change the behviour.
Exiftool does find the correct number of files and reports that all of them failed the condition, which isn't true.

StarGeek

I tested your command line and it worked as expected here.  Any chance you can copy and paste some examples showing the command line and output from a file or two?

The only things I can think of is that there's a minor error in your command or maybe the files have the DateTimeOriginal tag, but that it's blank.
* 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).

ULSWK

Your assumption is correct.
There are files in other directories without the datetimeoriginal field, but in my test directory it's there, but mostly empty.
Is there a different way to compare the field with a blank value ?

StarGeek

Deathrobot is dealing with a similar problem and I'd say their solution might work.  Grab the IF condition and change the single quotes to double quotes since you appear to be running Windows.

Edit:  My apologies, you mentioned in your first post that the tag could be empty.  I should pay better attention.
* 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).

ULSWK

 :) Thank's for your advice StarGeek !

I guess you are referring to this statement:
exiftool -if 'not defined $datetimeoriginal or $datetimeoriginal =~ /(^\s*$)/' "$1"

The general statement is easy to read, the ~ /(^\s*$)/' "$1" part is currently not understandable for me, but anyway. I'm currently in the office and will be glad to check if it works in my case this evening.

Thank you again for your advice.

StarGeek

tl;dr version
I double checked and you don't need to check to see if it's defined.  And the $1 part just has to do with Deathrobot's script, so it can be ignored.

So try this out:
exiftool -r -Overwrite_Original -Keywords+=AddDateTimeOrig -if "$datetimeoriginal =~ /(^\s*$)/" D:\Path\


extra long version:
Quotethe ~ /(^\s*$)/' "$1" part is currently not understandable for me,

To break it down,
=~ is the Perl operator for doing a Regular Expression match.  In this case it will take the expression between the slashes and compare it to the DateTimeOriginal tag. 
(^\s*$) is the Regular Expression that we're trying to match.  Normally, the parenthesis () wouldn't be needed, but ExifTool uses $/ as a replacement for a new line, so that's just a safe way of making sure things don't mess up. 

Now, to break down the rest of it.  The caret ^ marks the start of the tag.  the \s matches any whitespace (space, carriage return, newline, tab, formfeed), the asterisk says match the previous character between zero and unlimited times, as many times as possible, and the dollar sign is the end of the tag.

So basically, if the tag only contains any number of whitespace and only whitespaces, including none, then we have a match and we'll add your keyword.
* 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).

ULSWK

#8
Hi StarGeek,
thank's for your explanation, but it still doesn't work.
Not with your original code, and not with this modified code:
exiftool -r -Overwrite_Original -Keywords+=AddDateTimeOrig -if "not defined $datetimeoriginal or  $datetimeoriginal =~ /(^\s*$)/" D:\path\
exiftool replies that all files failed the condition.
May I send you one example jpeg file ??
If so, how ?


StarGeek

Check messages.

It would be helpful to see the output.  Could you run the command again but add | Clip to the end of the line?  This is a Windows command that will take the output of ExifTool and put it in the clipboard.  You can then paste the output here.
* 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).

ULSWK

Hi, the example file is below my last post and this is the output from the clipboard.

    1 directories scanned
   30 files failed condition
    0 image files read

Phil Harvey

Quote from: StarGeek on February 17, 2015, 01:12:24 PM
It would be helpful to see the output.  Could you run the command again but add | Clip to the end of the line?  This is a Windows command that will take the output of ExifTool and put it in the clipboard.  You can then paste the output here.

Cool.  That is a very useful tip that I didn't know about.  And I couldn't ever figure out how to cut and paste from the cmd window.

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

Phil Harvey

Quote from: ULSWK on February 17, 2015, 01:16:05 PM
Hi, the example file is below my last post and this is the output from the clipboard.

    1 directories scanned
   30 files failed condition
    0 image files read

The file you attached fails the condition because it contains DateTimeOriginal:

> exiftool ~/Desktop/20141007_61_6303.jpg -datetimeoriginal
Date/Time Original              : 2014:10:07 19:45:58


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

ULSWK

Wow,
that is really strange.
@Phil: Please have a look at the attached screenshot of the metadata panel from the photo I posted.
It is from adobe bridge. The red labeld fields should be DateTimeOriginal und CreationDate (sorry, the screenshot is german, I don't have an english version).
I've got many photos with correctly shown metadata in these two fields, but badly even many photos without this information.
Because bridge and/or lightroom can't filter or sort the files using this tag, I tried to tag them with a special keyword using exiftool, which I can filter easily in both tools.
Now, datetimeoriginal is obviously there, but not shown.

Can you help me to solve this confusion ?

StarGeek

Can you attach an image that Bridge does show the date for?
* 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).

StarGeek

Quote from: Phil Harvey on February 17, 2015, 03:01:09 PM
Cool.  That is a very useful tip that I didn't know about.  And I couldn't ever figure out how to cut and paste from the cmd window.

I had forgotten but it's available with Vista and newer, not XP.  But I think it can be downloaded in that case.

Windows command line is just so annoying when it comes to copy and pasting.  There are a lot of replacements that add this functionality, but MS can't seem to do it themselves.
* 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).

Phil Harvey

Quote from: ULSWK on February 17, 2015, 04:45:18 PM
Can you help me to solve this confusion ?

FAQ 3 helps with the problem of trying to figure out what metadata is displayed by other software.

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

ULSWK

Sure. Please find it attached.
I attached the bridge information as well.
I posted the photos in low resolution due to my bandwith. You can see that the photo has been exported a frew minutes ago (green mark) and the two original (red marked) creation dates.

StarGeek

I see a few differences in the date and time stamps.  The second picture that shows the date in Bridge has XMP:DateCreated, GPS:GPSTimeStamp, GPS:GPSDateStamp, IPTC:DateCreated, and IPTC:TimeCreated tags.  The first picture doesn't have these tags.

I created three copies of the first picture and copied the DateTimeOriginal into these missing tags.  Load them up in Bridge and see if any of them now show the DateTimeOriginal in it (I'm guessing it will be the xmp one).

XMP Changed : https://www.dropbox.com/s/6i16hw18nu5u0ws/XMP_20141007_61_6303.jpg
IPTC Changed : https://www.dropbox.com/s/lm2u0tulfc7wzwa/IPTC_20141007_61_6303.jpg
GPS Changed : https://www.dropbox.com/s/1e95c56t098t8xw/GPS_20141007_61_6303.jpg

Here are the commands I used.  If any of these show up properly, you can use the appropriate command to fix the rest of the files.

exiftool -overwrite_original "-XMP:DateCreated<DateTimeOriginal"

exiftool -overwrite_original "-IPTC:TimeCreated<DateTimeOriginal" "-IPTC:DateCreated<DateTimeOriginal"

exiftool -overwrite_original "-GPSTimeStamp<DateTimeOriginal" "-GPSDateStamp<DateTimeOriginal"
* 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).

ULSWK

That is interessing !
The file change date (marked blue) differs by some seconds because you saved the files one after each other, but the shown creation dates (marked red again) are equal for all three files.
Does this mean that bridge is showing different tags there, depending on what it can find in the file ??

ULSWK

An Addition to my last post:
Maybe I found a bug or at least strange behaviour of bridge.
I did some additional test on a small test directory with 38 files with this batch:

cls
@echo on
D:\#BV\TOOLS\EXIFTOOL\exiftool  -Overwrite_Original -Keywords+=AddDateTimeOriginal -if "not defined $datetimeoriginal or  $datetimeoriginal =~ /(^\s*$)/" "D:\#B\TEST\*.*"
D:\#BV\TOOLS\EXIFTOOL\exiftool  -Overwrite_Original -Keywords+=XMP_DateCreated -if "not defined $XMP:DateCreated or $XMP:DateCreated =~ /(^\s*$)/" "D:\#B\TEST\*.*"
D:\#BV\TOOLS\EXIFTOOL\exiftool  -Overwrite_Original -Keywords+=IPTC_TimeCreated -if "not defined $IPTC:TimeCreated or $IPTC:TimeCreated =~ /(^\s*$)/" "D:\#B\TEST\*.*"
pause


1.
The file I was missing the datestamp obviously has the datetimecreation date (as phil found out), but not the IPTC nor the XMP date stamps.

2.
After running the batch (and adding the keywords - and only the keywords - this way), bridge shows the date I was missing !! at the expected place (marked green in the attachmend)

A very strange behaviour, but I will find out how to handle this.

3.
Exiftool scanned all files twice !
I guess this is related to my "OR" statment. This causes doubled assigned keywords, can you please give me a hint how to supress that ? Two equal keywords in a file is not so nice.

ULSWK

Another question:

By the way, thank you very very much for your great advice !! This thread is very helpful for me. !!!

Most of my files have a correct date in the filename. like: YYYYDDMM_xx_#### where YYYYDDMM is the date, xx is a type sign and #### a number

Is it possible to assign the first 8 chars of the filename to the datetimecreation field ? This would reduce the amount of typo work.

Phil Harvey

Quote from: ULSWK on February 18, 2015, 06:37:38 AM
Most of my files have a correct date in the filename. like: YYYYDDMM_xx_#### where YYYYDDMM is the date, xx is a type sign and #### a number

Is it possible to assign the first 8 chars of the filename to the datetimecreation field ? This would reduce the amount of typo work.

Almost this exact question was asked and answered yesterday in this thread.  The only difference is that you would use s/_.*// instead of s/-.*// since you are using an underline at the end of the date/time part.

- Phil

Edit:  Oops.  Did you really mean YYYYDDMM, not YYYYMMDD?  Re-arranging the order is possible, but the expression would be more complicated: s/(\d{4})(\d{2})(\d{2}).*/$1$3$2/
...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 ($).

StarGeek

Quote from: ULSWK on February 18, 2015, 05:37:04 AM
2.
After running the batch (and adding the keywords - and only the keywords - this way), bridge shows the date I was missing !! at the expected place (marked green in the attachmend)

A very strange behaviour, but I will find out how to handle this.

Does Bridge have a reload metadata function?  It sounds like when these files were first imported, it didn't grab the info for some reason.  When you made a change, it reloaded all the info.

If Bridge doesn't have a reload function, on a different file that still doesn't show the date, try this command.  It will add one second to the system FileModifyDate, making it look like the file has been updated.  That might trick Bridge into thinking the file has been changed and needs to be updated

exiftool -FileModifyDate+="0:0:1" FILE



Quote3. Exiftool scanned all files twice !
I guess this is related to my "OR" statment. This causes doubled assigned keywords, can you please give me a hint how to supress that ? Two equal keywords in a file is not so nice.

That shouldn't be the case.  It should only add the keyword once regardless of how many ORs are in the condition.   But if you run it again without fixing the missing tag, it will add another copy of the keyword.  Run the command 5 times and you'll have 5 copies of the keyword.  To avoid multiple copies with multiple runs, you can either add another condition to the IF statement (like or keywords!~/AddDateTimeOriginal|XMP_DateCreated|IPTC_TimeCreated/) or the example in FAQ 17 (scroll down to where it says "To prevent duplication").
* 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).

ULSWK

Hi StarGeek,
yes, it is possible to reload the metadata in bridge but it ends up with the same values as before.
I'll try to find out about that in a adobe forum.
Perhaps someone knows the behaviour rules. I guess try and error might take a while...

Regarding the doubled keywords: Your statement "or keywords!~/AddDateTimeOriginal|XMP_DateCreated|IPTC_TimeCreated/)" seems to work fine.
Thank you !!