ExifTool Forum

ExifTool => The "exiftool" Application => Topic started by: Atai Lo on April 08, 2021, 02:13:50 AM

Title: How to change exif time / creation time to match the file name?
Post by: Atai Lo on April 08, 2021, 02:13:50 AM
Hi all,
I have lots of photos in ".jpg" and ".png".
The photos have filename based on the right photo time like "2012-02-12 19.52.52.jpg" or "2012-02-04 23.59.54.png".

(1) for jpg
Now I can change the EXIF time for jpg by code:    exiftool "-datetimeoriginal<filename" -d "%Y-%M-%D %H.%M.%S.%%e" ./
Also I tried to change modify time and creation time by file name, however my filename format is not "YYYYmmdd_HHMMSS"
so the code     exiftool "-AllDates<filename" *  does not work is there any way without change file name format first?

(2) for png
I tried to change the modify time or creation time for png, and I referenced this article  https://exiftool.org/forum/index.php?topic=8831.0
the suggestion code   exiftool "-PNG:CreationTime<{filename;s/(\d{4})-(\d\d)-(\d\d) (\d\d).(\d\d).(\d\d).*/$1:$2:$3 $4:$5:$6/}"  does not work for me.
I am not sure if it causes by the new version.


Could anyone give some ideas for this. Any suggestion is appreciated!

Thanks!
Atai
Title: Re: How to change exif time / creation time to match the file name?
Post by: Luuk2005 on April 08, 2021, 02:44:05 AM
Sorry, Im reading many times, but cannot understand the question inside '(1) for jpg'  ????
But for png its just looking like typo, because it should look like.... ${filename;

Edit: For the jpegs, to use something like -AllDates"<${Filename; s/YourFormat/GoodFormat/}" but this impossible to advise without knowing YourFormat.
Example: if YourFormat was like mm-dd-YYYY HH.MM.SS, then to use something like...
-AllDates"<${Filename;s/.*(\d\d)-(\d\d)-(\d\d\d\d) (\d\d)\.(\d\d)\.(\d\d).*/$3$1$2 $4$5$6/}"
Title: Re: How to change exif time / creation time to match the file name?
Post by: StarGeek on April 08, 2021, 10:59:54 AM
Quote from: Atai Lo on April 08, 2021, 02:13:50 AM
The photos have filename based on the right photo time like "2012-02-12 19.52.52.jpg" or "2012-02-04 23.59.54.png".
...
however my filename format is not "YYYYmmdd_HHMMSS"
so the code     exiftool "-AllDates<filename" *  does not work is there any way without change file name format first?

I don't understand.  Both your examples have Year Month Day Hour Minutes Seconds in the proper order.  As per FAQ #5 (https://exiftool.org/faq.html#Q5), all you need is
exiftool "-alldates<filename" c:\images
Use of the -d (dateFormat) option (https://exiftool.org/exiftool_pod.html#d-FMT--dateFormat) is unnecessary.

For PNGs, you just need to add
-PNG:CreationTime<Filename

Example output
C:\>exiftool -P -overwrite_original "-AllDates<Filename" "-PNG:CreationTime<Filename" Y:\!temp\ccccc\p
    1 directories scanned
    2 image files updated
C:\>exiftool -time:all -G1 -a -s Y:\!temp\ccccc\p
======== Y:/!temp/ccccc/p/2012-02-04 23.59.54.png
[File]          FileModifyDate                  : 2020:04:28 19:27:38-07:00
[File]          FileAccessDate                  : 2020:04:28 12:30:38-07:00
[File]          FileCreateDate                  : 2020:04:28 12:30:38-07:00
[PNG]           CreationTime                    : 2012:02:04 23:59:54
[PNG]           CreateDate                      : 2012:02:04 23:59:54
[PNG]           ModifyDate                      : 2012:02:04 23:59:54
[EXIF]          ModifyDate                      : 2012:02:04 23:59:54
[EXIF]          DateTimeOriginal                : 2012:02:04 23:59:54
[EXIF]          CreateDate                      : 2012:02:04 23:59:54
======== Y:/!temp/ccccc/p/2012-02-12 19.52.52.jpg
[File]          FileModifyDate                  : 2016:06:03 22:29:58-07:00
[File]          FileAccessDate                  : 2020:08:30 09:06:08-07:00
[File]          FileCreateDate                  : 2020:08:30 09:06:07-07:00
[EXIF]          ModifyDate                      : 2012:02:12 19:52:52
[EXIF]          DateTimeOriginal                : 2012:02:12 19:52:52
[EXIF]          CreateDate                      : 2012:02:12 19:52:52
    1 directories scanned
    2 image files read


As you can see, all the tags affected by AllDates (CreateDate/DateTimeOriginal/ModifyDate, see AllDates entry on the Shortcut tag page (https://exiftool.org/TagNames/Shortcuts.html)) have been updated and the PNG:CreationTime has also been updated in the PNG file.
Title: Re: How to change exif time / creation time to match the file name?
Post by: Atai Lo on April 11, 2021, 06:21:22 PM
To StarGeek

I use the code   exiftool "-PNG:CreationTime<Filename"
then the png file got the creation time from filename
thanks a lot!!!