ExifTool Forum

ExifTool => The "exiftool" Application => Topic started by: Per on December 11, 2017, 04:31:50 AM

Title: Find and update files where filename and datetimeoriginal do not match
Post by: Per on December 11, 2017, 04:31:50 AM
Hello  :)
After reading several threads without any luck, I hope someone can help me with following problem.

I am trying to find and update datetimeoriginal for files where it doesn't match the date and time stated in the file name.
The file names are all formatted like this: 1960-06-24 121600 Summer festival.jpg
I have tried following syntax, but it seems to update all files, not only those that do not match.

exiftool '-alldates<filename' -if '$datetimeoriginal ne $filename' /Users/Per/Pictures/Test

Can anybody help?

Brgds Per
Title: Re: Find and update files where filename and datetimeoriginal do not match
Post by: Phil Harvey on December 11, 2017, 07:08:09 AM
Hi Per,

3 things:

1. Your command should work to update EXIF DateTimeOriginal, CreateDate and ModifyDate.

2. In general, you can't set dates before 1970 because of limitations in the standard date/time library functions.  However, I just tried this on OS X 10.10.5 for the date/time in your example and it worked.

3. Your -if condition will always be true since the formatting of the filename is different than the EXIF date/time formatting used by ExifTool.  Plus, the file name will likely have an extension.

- Phil
Title: Re: Find and update files where filename and datetimeoriginal do not match
Post by: Per on December 11, 2017, 12:12:00 PM
Hi Phil  :)
Thanks a lot for a quick reply  :)
So for this to work, I have to change the date and time format in the filename. I'll try that.
Brgds Per  :)
Title: Re: Find and update files where filename and datetimeoriginal do not match
Post by: Per on December 11, 2017, 12:20:32 PM
I think I got it now  ::) I need to extract the date and time from the filename for comparing.
Is that possible?
Brgds Per
Title: Re: Find and update files where filename and datetimeoriginal do not match
Post by: Phil Harvey on December 11, 2017, 01:43:42 PM
I don't think you need to worry about the -if at all.  If the file name is the same, exiftool does nothing anyway.  So you aren't saving anything with the -if.

- Phil
Title: Re: Find and update files where filename and datetimeoriginal do not match
Post by: Fulco on December 11, 2017, 04:06:06 PM
This is the command I use to find and update DateTimeOriginal for files which don't match the date and time stated in the file name:

exiftool -if '${FileName;s/^(\d{4}-\d{2}-\d{2} \d{6})\..*/$1/} ne ${DateTimeOriginal;DateFmt("%Y-%m-%d %H%M%S")}' '-FileName>AllDates' -overwrite_original


Test files:

exiftool -FileName -alldates -d "%Y-%m-%d %H%M%S" /Users/Fulco/Test
======== /Users/Fulco/Test/1981-06-24 121600.JPG
File Name                       : 1981-06-24 121600.JPG
Date/Time Original              : 1980-06-24 121600
Create Date                     : 1980-06-24 121600
Modify Date                     : 1980-06-24 121600
======== /Users/Fulco/Test/1980-06-24 121600.JPG
File Name                       : 1980-06-24 121600.JPG
Date/Time Original              : 1980-06-24 121600
Create Date                     : 1980-06-24 121600
Modify Date                     : 1980-06-24 121600
    1 directories scanned
    2 image files read



Find files which don't match the date and time stated in the file name:

exiftool -if '${FileName;s/^(\d{4}-\d{2}-\d{2} \d{6})\..*/$1/} ne ${DateTimeOriginal;DateFmt("%Y-%m-%d %H%M%S")}' -Filename /Users/Fulco/Test
======== /Users/Fulco/Test/1981-06-24 121600.JPG
File Name                       : 1981-06-24 121600.JPG
    1 directories scanned
    1 files failed condition
    1 image files read
[


Find and update DateTimeOriginal for files where it doesn't match the date and time stated in the file name:

exiftool -if '${FileName;s/^(\d{4}-\d{2}-\d{2} \d{6})\..*/$1/} ne ${DateTimeOriginal;DateFmt("%Y-%m-%d %H%M%S")}' '-FileName>AllDates' -overwrite_original /Users/Fulco/Test
    1 directories scanned
    1 files failed condition
    1 image files updated



Result:

exiftool -Filename -alldates -d "%Y-%m-%d %H%M%S" /Users/Fulco/Test
======== /Users/Fulco/Test/1981-06-24 121600.JPG
File Name                       : 1981-06-24 121600.JPG
Date/Time Original              : 1981-06-24 121600
Create Date                     : 1981-06-24 121600
Modify Date                     : 1981-06-24 121600
======== /Users/Fulco/Test/1980-06-24 121600.JPG
File Name                       : 1980-06-24 121600.JPG
Date/Time Original              : 1980-06-24 121600
Create Date                     : 1980-06-24 121600
Modify Date                     : 1980-06-24 121600
    1 directories scanned
    2 image files read



Disclaimer: I'am not an advanced Exiftool user. Better is that Phil will first have a look at these commands before using it.

- Fulco
Title: Re: Find and update files where filename and datetimeoriginal do not match
Post by: Phil Harvey on December 12, 2017, 08:47:59 AM
Ah, right.  You're setting alldates from FileName.  I was thinking the other way around.  So my comment about the -if was wrong.

Quote from: Fulco on December 11, 2017, 04:06:06 PM
This is the command I use to find and update DateTimeOriginal for files which don't match the date and time stated in the file name:

exiftool -if '${FileName;s/^(\d{4}-\d{2}-\d{2} \d{6})\..*/$1/} ne ${DateTimeOriginal;DateFmt("%Y-%m-%d %H%M%S")}' '-FileName>AllDates' -overwrite_original

Looks good.

- Phil
Title: Re: Find and update files where filename and datetimeoriginal do not match
Post by: Per on December 12, 2017, 01:00:49 PM
Thanks a lot Phil and Fulco  :)
I will test Fulco's solution asap. But as I am not a professionel programmer, I have to read about Perl programming language first. Especially about string function.
Brgds Per
Title: Re: Find and update files where filename and datetimeoriginal do not match
Post by: Per on December 13, 2017, 11:33:41 AM
Hi
I am sorry but it doesn't work for me. I get this:

Pers-MacBook-Pro-2:~ Per$ exiftool -if '${FileName;s/^(\d{4}-\d{2}-\d{2} \d{6})\..*/$1/} ne ${DateTimeOriginal;DateFmt("%Y-%m-%d %H%M%S")}' -FileName /Users/Per/Pictures/Test
======== /Users/Per/Pictures/Test/1980-06-24 000000 test 2.jpg
File Name                       : 1980-06-24 000000 test 2.jpg
======== /Users/Per/Pictures/Test/1970-06-24 000000 test 1.jpg
File Name                       : 1970-06-24 000000 test 1.jpg
    1 directories scanned
    2 image files read

Can't I use Substr to find the first 17 characters in the filename?

Brgds Per

Title: Re: Find and update files where filename and datetimeoriginal do not match
Post by: Per on December 13, 2017, 12:14:23 PM
Finally I got it right  :D

I used Substr like this:

exiftool -if '${filename;$_=substr($_,0,17)} ne ${DateTimeOriginal;DateFmt("%Y-%m-%d %H%M%S")}' '-FileName>AllDates' -overwrite_original  /Users/Per/Pictures/Test

Thanks again for your kind help

Brgds Per
Title: Re: Find and update files where filename and datetimeoriginal do not match
Post by: go on January 09, 2025, 06:31:41 AM
WOW, ok this is exactly what I want to do as well.  However my files are formatted as:

2018_10_30_112437_.JPG

Which I think is year_month_date_time and then either jpg or mp4

How can I modify the above to get it to work for me as well?  LOVE to get a response please thank you!!!!
Title: Re: Find and update files where filename and datetimeoriginal do not match
Post by: Phil Harvey on January 09, 2025, 06:48:51 AM
I would suggest simply:

exiftool "-alldates<filename" DIR

You don't need the -if statement unless you don't want to process files that already contain date/time tags.  And in that case, something simpler like this should do:

exiftool "-alldates<filename" -if "not $createdate" DIR

which won't process files that contain the CreateDate tag.  Alternatively, you can avoid overwriting existing tags like this:

exiftool "-alldates<filename" -wm cg DIR

- Phil
Title: Re: Find and update files where filename and datetimeoriginal do not match
Post by: go on January 09, 2025, 06:55:04 AM
Wow what a fast response, thank you.  So I just put that command and either drop in files or add a directory?

What I want is to update all the dates in the EXIF to the filename, if the createdate doesn't match the filename.  Somehow some files createdate/date created have changed so in some photo applications, the order when sorted by shotdate/createdate, don't make sense...

Essentially to dumb it down to my brain level:
If EXIF date doesn't match filename date
Then write all EXIF dates to match filename

If EXIF date matches filename
Then ignore

Something like this?
Title: Re: Find and update files where filename and datetimeoriginal do not match
Post by: Phil Harvey on January 09, 2025, 09:22:16 PM
OK, so you do want the complicated -if statement:

exiftool -if "$basename ne ${DateTimeOriginal;DateFmt('%Y_%m_%d_%H%M%S_')}"
"-alldates<filename" DIR


(Note:  I've used quoting appropriate for the Windows cmd shell.)

- Phil

Edit: Oops. Quoting was actually wrong.  Fixed now.
Title: Re: Find and update files where filename and datetimeoriginal do not match
Post by: go on January 10, 2025, 03:32:00 AM
Thanks Phil, I'll give that a try. I was trying to figure out the structure of the if statements, but had no idea even after reading everywhere online.  Well beyond my capabilities!!