Set the DateTimeOriginal from the file name

Started by asoupper, February 07, 2013, 09:45:22 AM

Previous topic - Next topic

asoupper

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

Phil Harvey

Hi Alban,

You can use this command:

exiftool "-datetimeoriginal<filename" FILE

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

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

asoupper

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

Phil Harvey

Hi Alban,

It means that your metadata is corrupted.  See FAQ 20 for details about how to fix this.

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

asoupper

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

gpsr

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!

Hayo Baan

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.
Hayo Baan – Photography
Web: www.hayobaan.nl

Phil Harvey

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

Hayo Baan

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 :)
Hayo Baan – Photography
Web: www.hayobaan.nl