News:

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

Main Menu

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