ExifTool Forum

ExifTool => The "exiftool" Application => Topic started by: asoupper on February 07, 2013, 09:45:22 AM

Title: Set the DateTimeOriginal from the file name
Post by: asoupper on February 07, 2013, 09:45:22 AM
Hello,
I have some pictures that had their DateTimeOriginal corrupted or erased.
Hopefully, their names are in this form: 2012-07-23_10.08.46.jpg.

How to restore the EXIF original date using the filename?

Thanks,
Alban
Title: Re: Set the DateTimeOriginal from the file name
Post by: Phil Harvey on February 07, 2013, 09:46:48 AM
Hi Alban,

You can use this command:

exiftool "-datetimeoriginal<filename" FILE

were FILE is one or more file names or directory names.

- Phil
Title: Re: Set the DateTimeOriginal from the file name
Post by: asoupper on February 07, 2013, 11:09:24 AM
Thanks Phil,
Unfortunately I get the following error message:
Warning: Invalid EXIF text encoding - 2012-07-25 21.51.06.jpg
Error: Error reading OtherImageStart data in ExifIFD - 2012-07-25 21.51.06.jpg

What does it mean?
Alban
Title: Re: Set the DateTimeOriginal from the file name
Post by: Phil Harvey on February 07, 2013, 11:20:38 AM
Hi Alban,

It means that your metadata is corrupted.  See FAQ 20 (https://exiftool.org/faq.html#Q20) for details about how to fix this.

- Phil
Title: Re: Set the DateTimeOriginal from the file name
Post by: asoupper on February 07, 2013, 11:22:16 AM
The answer was in the FAQ (as usual  :o )
This
exiftool -all= -tagsfromfile @ -all:all -unsafe 2012-07-25\ 21.51.06.jpg
corrected the file!
Then your command set correctly the date.

Thanks 1000000 times for your software
Alban
Title: Re: Set the DateTimeOriginal from the file name
Post by: gpsr on August 07, 2014, 01:59:15 PM
Hi
I am in a similar situation. I have a file named 09-03-06.jpg. It lacks any exif data whatsoever. So I tried adding the datetimeoriginal to  it with the following command in a .bat file placed in the image containing folder itself:

exiftool -if "not defined $DateTimeOriginal" "-DateTimeOriginal<FileName" "09-03-06.jpg"

But I get the error:

Warning: Invalid date/time (use YYYY:mm:dd HH:MM:SS[.ss][+/-HH:MM|Z]) in ExifIFD:DateTimeOriginal (PrintConvInv)

Please Help!
Title: Re: Set the DateTimeOriginal from the file name
Post by: Hayo Baan on August 07, 2014, 03:25:50 PM
The year needs 4 digits (YYYY), and you also need to specify a time. Plus it looks like you forgot a $ in front of Filename.

With a bit of advanced exiftool magic, you may, however be able to pull it off:
exiftool -if "not defined $DateTimeOriginal" "-DateTimeOriginal<${FileName;s/^/20/;s/$/ 00:00:00}" "09-03-06.jpg"
This prefixes the filename with 20 for the century and also adds 00:00:00 for the time.
Title: Re: Set the DateTimeOriginal from the file name
Post by: Phil Harvey on August 15, 2014, 06:55:06 PM
Just two minor points:

1) "-DateTimeOriginal<FileName" is correct, and is the simple form used to copy a tag without modification.

2) Adding the "20" to the start, and the time to the end could be done a bit more simply (without the advanced formatting feature), like this:

"-DateTimeOriginal<20${FileName} 00:00:00"

- Phil

BTW, Hayo: thanks for all your help on the forum
Title: Re: Set the DateTimeOriginal from the file name
Post by: Hayo Baan on August 16, 2014, 06:41:25 AM
Quote from: Phil Harvey on August 15, 2014, 06:55:06 PM
Just two minor points:

1) "-DateTimeOriginal<FileName" is correct, and is the simple form used to copy a tag without modification.

2) Adding the "20" to the start, and the time to the end could be done a bit more simply (without the advanced formatting feature), like this:

"-DateTimeOriginal<20${FileName} 00:00:00"

Ah, true of course, should've thought about that.

Quote from: Phil Harvey on August 15, 2014, 06:55:06 PM
BTW, Hayo: thanks for all your help on the forum
You're more than welcome; it also helps me learn some new stuff so we all benefit :)