ExifTool Forum

ExifTool => Newbies => Topic started by: hansherlighed on September 30, 2019, 03:46:18 PM

Title: Set "DateTimeOriginal" tag from filename and move file
Post by: hansherlighed on September 30, 2019, 03:46:18 PM
Hi,

I have some files where all time tags are incorrect due to different reasons. The filename however is the correct date and time of when the photo was taken.

I'm trying to set the "-AllDates" tag from filename AND move the files into my desired folder structure in 1 go. However I'm not having any luck. It seems that exiftool renames/moves the files first and then sets/updates the tags.

Example(This is a screenshot taken on an iPhone):
exiftool -time:all -G1 -a /test/20190930_211659000.png

======== /test/20190930_211659000.png
[System]        File Modification Date/Time     : 2019:09:30 21:17:53+02:00
[System]        File Access Date/Time           : 2019:09:30 21:17:53+02:00
[System]        File Inode Change Date/Time     : 2019:09:30 21:17:53+02:00
[ICC-header]    Profile Date Time               : 2017:07:07 13:22:32
[XMP-photoshop] Date Created                    : 2019:09:30 21:16:59

In this case the "XMP-PHOTOSHOP" tag holds the correct date and time, but this is not true in all(most) of my files. Most of them do not have any tags. Also the filename might contain milliseconds or suffixes and/or prefixes, so a 1-1 move of the files is not an option, I want to rename them with the specified "-d" format when moving them, to make sure all photos end up with the same name format.

I tried using this command:
/usr/local/bin/exiftool -P -ee -overwrite_original -d /tmp/%Y%m%d_%H%M%S%%-c.%%e -ext jpg '-FileName<FileModifyDate' '-AllDates<filename' /test/
I've also tried using '-FileModifyDate<filename' instead of '-AllDates<filename', but it's the same result.

The tags get updated, but the file is moved and renamed using the original "FileModifyDate" value instead of the new:

======== /test/20190930_211659000.png
Setting new values from /test/20190930_211659000.png
Warning: Use of uninitialized value in join or string in Reconyx:DateTimeOriginal (ValueConvInv) - /test/20190930_211659000.png
'/test/20190930_211659000.png' --> '/tmp/20190930_211753.png'
Rewriting /test/20190930_211659000.png...
  Editing tags in: ExifIFD File IFD0 MIE-Doc MakerNotes PDF PNG PostScript QuickTime UserData XMP
  FileType = PNG
  FileTypeExtension = PNG
  MIMEType = image/png
PNG IHDR (13 bytes):
PNG iCCP (353 bytes):
  + [iCCP directory]
PNG iTXt (495 bytes):
  Rewriting XMP
PNG IDAT (189 chunks, total 3088074 bytes)
Creating eXIf chunk:
  Creating IFD0
  Creating ExifIFD
PNG IEND (end of image)
    1 image files updated



Is there anyway to make exiftool update/write the tags first, and then use the new values to move/rename the file, or do I need to do this in 2 commands(1 to set the tags and 1 to rename/move the files)?

Thanks
//Morten
Title: Re: Set "DateTimeOriginal" tag from filename and move file
Post by: Phil Harvey on September 30, 2019, 03:58:39 PM
Hi Morten,

It would be easiest to do this in 2 commands, but they may be combined into a single command line:

exiftool -P -overwrite_original '-alldates<filename' -execute -d /tmp/%Y%m%d_%H%M%S%%-c.%%e '-filename<datetimeoriginal' -common_args -ext jpg /test

Note that writing AllDates doesn't write FileModifyDate.  It writes DateTimeOriginal, CreateDate and ModifyDate.  So I have renamed based on DateTimeOriginal.

- Phil
Title: Re: Set "DateTimeOriginal" tag from filename and move file
Post by: hansherlighed on October 01, 2019, 01:11:05 AM
Hi Phil,

Thanks for the 1 liner it works like a charm.
Title: Re: Set "DateTimeOriginal" tag from filename and move file
Post by: hansherlighed on October 01, 2019, 08:40:16 AM
Hi again,

Another question. Since I know the date is correct in the filename, I expected to be able to do '-filename<filename' and the photo would be renamed according to my -d value. But that's not the case. Instead the photo is not being renamed and exiftool shows "Filename is not changed".
Is it possible to somehow use '-filename<filename' but have the new filename be formatted according to -d?

Thanks
//Morten
Title: Re: Set "DateTimeOriginal" tag from filename and move file
Post by: Phil Harvey on October 01, 2019, 08:44:21 AM
Hi Morten,

The -d option only applies to date/time tags.  When reading/writing FileName, no date/time formatting is imposed.

- Phil