ExifTool Forum

ExifTool => Newbies => Topic started by: tharindusathis on March 24, 2019, 03:10:41 AM

Title: Setting "Date taken" attribute of JPEG Image, from the File name.
Post by: tharindusathis on March 24, 2019, 03:10:41 AM
I have set of JPEG image files which don't have values in "Date taken" attribute. But the JPEG file has the date of image taken.

E.g.:  my_image_1@11-02-2018_22-21-16.jpg
Here Image taken date is 2018/02/11 and time is 22:21:16.

What I need is to set the "Date taken" attribute of all photos (I need to do it for all photos at once). Is it possible to do with this tool? Can you please explain me the method?

Note: I'm very new to this toll and I appreciate your help to do my work. Thank you.
Title: Re: Setting "Date taken" attribute of JPEG Image, from the File name.
Post by: StarGeek on March 24, 2019, 03:27:24 AM
Normally, FAQ #5 (https://exiftool.org/faq.html#Q5), paragraph 3 would be the answer, but in your case, you have a number in the file name before the date and the date itself isn't in a YearMonthDay sequence.  So some reordering of the numbers will be necessary.

Try this on a test file to see if it works for you
exiftool "-AllDates<${filename;s/.*@(\d\d)-(\d\d)-(\d{4})(.*)/$3 $1 $2 $4/}" FileOrDir

This command will strip away everything up to and including the @ sign, then match and reorder the dates, and then match the rest of the filename.  This should make sure the numbers are in YYYY MM DD HH mm SS order.  Exiftool will ignore any extra characters when assigning the timestamp, as mentioned in FAQ 5.  If any file does not match this pattern, the results will not be correct.

This command will create backup files.  Add the Overwrite_Original option (https://exiftool.org/exiftool_pod.html#overwrite_original) to prevent that.  Add the -r option (https://exiftool.org/exiftool_pod.html#r-.--recurse) to recurse into subdirectories.
Title: Re: Setting "Date taken" attribute of JPEG Image, from the File name.
Post by: tharindusathis on March 24, 2019, 04:21:20 AM
I found this and It worked!


exiftool
"-datetimeoriginal<
${filename;$_=substr($_,14,4)}:
${filename;$_=substr($_,11,2)}:
${filename;$_=substr($_,8,2)}:
${filename;$_=substr($_,19,2)}:
${filename;$_=substr($_,22,2)}:
${filename;$_=substr($_,25,2)}
+05:30" photo_1@11-02-2018_22-21-16.jpg"


Note: Here +05:30 for timezone.
Title: Re: Setting "Date taken" attribute of JPEG Image, from the File name.
Post by: StarGeek on March 24, 2019, 12:44:23 PM
I notice I incorrectly listed the command, as I forgot the opening BBcode.  That's now been corrected.

Quote from: tharindusathis on March 24, 2019, 04:21:20 AM
Note: Here +05:30 for timezone.

Just so you know, the addition of the time zone won't be saved, as that particular tag doesn't hold the time zone.  To place to write the time zone so that it matches up with DateTimeOriginal is OffsetTimeOriginal.