Author Topic: FileModifyDate is off by one second sometimes  (Read 2810 times)

jls3512

  • Jr. Member
  • **
  • Posts: 21
FileModifyDate is off by one second sometimes
« on: September 07, 2015, 09:28:28 AM »
I don't really think this is as much a bug as it is probably something to do with windows, but it's curious behavior so I thought I would ask about it. 


I'm using the following batch file to make all the dates in my photos the same as the create date... the only date I will ever care about,  when the photo was taken.

Code: [Select]
@echo off
Echo %~D1%~P1
Echo %*
set /P offset=Enter offset including + or -:
if "%offset%"=="0" goto :setdates
if "%offset%"=="+0" goto :setdates
if "%offset%"=="-0" goto :setdates

exiftool.exe -ext .dng -ext .jpg -ext .mp4 -ext .tif -ext .psd "-CreateDate%offset:~0,1%=%offset:~1%" -r -Overwrite_original -progress -m %*


:setdates
exiftool.exe -ext .dng -ext .jpg -ext .mp4 -ext .tif -ext .psd "-DateTimeOriginal<CreateDate" "-TrackCreateDate<CreateDate" "-TrackModifyDate<CreateDate" "-MediaCreateDate<CreateDate" "-MediaModifyDate<CreateDate" "-SonyDateTime<CreateDate" "-ModifyDate<CreateDate" "-FileCreateDate<CreateDate" "-FileModifyDate<CreateDate" -k -r -Overwrite_original -progress -m -q %*


On some, but not all of the files, when I go back and look at them,  the FileModifyDate is advanced by one second.   I don't understand why, because both FileCreateDate and FileModifyDate are copied from CreateDate and therefore should be identical.   File Size seems to have no bearing on this effect, it does it on 25MB .dng files as well as 2MB .jpg files... and when looking even at files in the same folder, of photos taken seconds of each other,  one will display this one second advance in FileModifyDate and the other will not.   I also notice that files showing the one second advance will always have it no matter how many times I run them, and files that do not show it never will no matter how many times I run those either.  I also tried changing createdate ahead and back in various increments from 1 hour to 5 hours and that also has no effect.  Also file type seems to make no difference,  I have examples both ways of .dng .arw .jpg .tif and .psd


My computer is Window 7 Professional

relevant hard drives:
C:  O/S  512GB SSD formatted NTFS
L:   Photo Storage 5TB internal hard drive formatted EXFAT

exiftool version 10.01


Alan Clifford

  • ExifTool Freak
  • *****
  • Posts: 479
    • A selection of Alan Clifford's photographs
Re: FileModifyDate is off by one second sometimes
« Reply #1 on: September 07, 2015, 07:31:03 PM »
Do windows filesystems still store their filestamps with a 2 second resolution?  FAT filesystems do I think.


Alan Clifford

  • ExifTool Freak
  • *****
  • Posts: 479
    • A selection of Alan Clifford's photographs
Re: FileModifyDate is off by one second sometimes
« Reply #2 on: September 07, 2015, 07:32:54 PM »

Hayo Baan

  • Global Moderator
  • ExifTool Freak
  • *****
  • Posts: 1140
  • Professional Photographer & Software Developer
    • Hayo Baan – Photography
Re: FileModifyDate is off by one second sometimes
« Reply #3 on: September 08, 2015, 02:56:51 AM »
I think Alan already provided you the answer on why this could happen. I would only add that I would strongly suggest to not rely on the file system's timestamps at all as they can easily get changed by just “touching” the files (editing, moving, etc.). Instead, I suggest you use the metadata fields inside the files themselves (that's what they are for!).
Hayo Baan – Photography
Web: www.hayobaan.nl

jls3512

  • Jr. Member
  • **
  • Posts: 21
Re: FileModifyDate is off by one second sometimes
« Reply #4 on: September 11, 2015, 03:11:28 PM »
Thanks for the information!  I would have never guessed that they carried that over in the relatively new ExFAT file system, which is way newer than NTFS.  Apparently they round to the nearest 2 seconds only in the  Date modified and date access fields, but they upgraded the date created field allow 1 second resolution.   Strange.    Thanks for figuring this out!   

I agree about using metatags instead, and most of my files do use the metatags, but I have some MTS movie files created by my digital camera that I can't write any metadata into, and unfortunately I took a whole ton of photos with it not realizing that the GPS had not yet corrected my timezone,  so they are all 5 hours out of sync with the rest of my photos take with other cameras.   Fixing the file time stamps gives me an easy way to see where the time is going wrong so I can fix it, because the time should increment in the numerical order the photos and/or videos were taken.   Unfortunately I can't fix DateCreated metatag in the MTS files, because even though Exiftool can read this,  it can't write it and in fact, it won't even write out the file create, modify, and access dates on mts files.   I guess I'll have to convert them to .mp4 files or something eventually.

James

Phil Harvey

  • ExifTool Author
  • Administrator
  • ExifTool Freak
  • *****
  • Posts: 16906
    • ExifTool Home Page
Re: FileModifyDate is off by one second sometimes
« Reply #5 on: September 11, 2015, 04:15:09 PM »
Hi James,

ExifTool should be able to write the filesystem date/time tags for any file type, but you need to either specify the file by name or add -ext m2t to the command if specifying a directory to get ExifTool to process the file.  (FAQ 16 explains why.)

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

jls3512

  • Jr. Member
  • **
  • Posts: 21
Re: FileModifyDate is off by one second sometimes
« Reply #6 on: September 11, 2015, 06:47:47 PM »
Thank you Phil, 

I did get it to work,  I figured I would post my findings so perhaps they will help someone else who was making the same error I was making.   Here's what was happening...
I was using this command:
Code: [Select]
exiftool.exe  -ext .dng -ext .jpg -ext .mp4 -ext .tif -ext .mts "-CreateDate<DateTimeOriginal" "-TrackCreateDate<DateTimeOriginal" "-TrackModifyDate<DateTimeOriginal" "-MediaCreateDate<DateTimeOriginal" "-MediaModifyDate<DateTimeOriginal" "-SonyDateTime<DateTimeOriginal" "-ModifyDate<DateTimeOriginal" "-FileCreateDate<DateTimeOriginal" "-FileModifyDate<DateTimeOriginal" -k -r -Overwrite_original -progress -m -q %*
trying to correct all my metadata in all applicable file types in one pass.. 
TrackCreateDate,TrackModifyDate, MediaCreateDate, and MediaModifyDate only exist in my MP4 files
SonyDateTime only exist for 2 of my Sony cameras  .JPG and .DNG files
Create Date exists in all files except .MTS
and DateTimeOriginal exists in all files including .MTS

with this command when the .mts files went through, it saw tags it could not write to, so it gave an error:
Error: Writing of MTS files is not yet supported

so I figured it could not write to the .MTS files at all,  I did read in the forum somewhere that there is no standard for .MTS files so it's rather pointless to try to support something that has no standard format,  I also noticed that it did not write the FileCreateDate or FileModifyDate
the reason I incorrectly figured it could not write the FileCreateDate and FileModifyDates is because other files will just ignore tags they don't have and modify the ones they do,  so if I run my sony .DNG file through the above command,  it does fix the SonyDateTime,  CreateDate, FileCreateDate, and FileModifyDate, but it just ignores TrackCreateDate,TrackModifyDate, MediaCreateDate, and MediaModifyDate without any warnings or errors... when it gets an .MP4 it ignores SonyDateTime and writes all the rest... etc.. Since the .MTS file didn't write anything at all and said it was not supported, I didn't even think to try:
Code: [Select]
exiftool.exe  -ext .mts "-FileCreateDate<DateTimeOriginal" "-FileModifyDate<DateTimeOriginal" -k -r -Overwrite_original -progress -m -q %*
which I just tried and I am very happy that it does indeed change FileCreateDate and FileModifyDate.

I was hoping to get it all done in one pass,  I had over 101,000 files to process, and it took a little over 10hours, and I'm happy to say that it worked perfectly on all but the .mts files which aren't really that many.    I can just do a dir *.mts /s /b > mtsfiles.txt and figure out where my .mts files are and just run those through a short run without going though them all again.

I'll be sure to take the -ext .mts off the original command line and add another line for just .mts files and it should be good.



Phil Harvey

  • ExifTool Author
  • Administrator
  • ExifTool Freak
  • *****
  • Posts: 16906
    • ExifTool Home Page
Re: FileModifyDate is off by one second sometimes
« Reply #7 on: September 13, 2015, 09:17:44 PM »
Ah.  That makes sense.  Yes, ExifTool will balk when trying to write "real" tags to an unsupported file.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).