News:

2023-03-15 Major improvements to the new Geolocation feature

Main Menu

Set the file modification and creation date from EXIF info

Started by Joseph Allan, April 28, 2013, 10:37:25 PM

Previous topic - Next topic

Joseph Allan

Hi.  I have been trying to work out the command line to set the file modification and creation date in Windows from EXIF information.  It's listed as one of the features I cannot find any examples or any gui programs that will do it for me.  The reason for doing this that Adobe Photoshop Lightroom does not pick up the EXIF information in VIDEO files and uses either the file modification or creation date for capture time (can't remember which).  To get around this I use ROBOCOPY to preserve the dates - but my new Samsung S3 does not allow a drive letter connection (must connect using MTP Media Transfer Protocol).  When transferring the files from the phone Windows gives a new modified and created date.

Can anyone help?

StarGeek

Quote from: josephallan on April 28, 2013, 10:37:25 PM
Hi.  I have been trying to work out the command line to set the file modification and creation date in Windows from EXIF information.

Check out Faq question 24, esp. near the end.

Basically, I think you want something like

ExifTool "-FileCreateDate<DateTimeOriginal" "-FileModifyDate<DateTimeOriginal"  file

Though it's late right now for me, my brain is a bit fuzzy, and I'm not quite sure on which would be the correct tag you want to put in there.  Hopefully that will give you something to start with.
* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).

Joseph Allan

Thanks!  I followed the FAQ to first produce a list of where the dates are stored then updated the file. 


D:\temp\vids\x>exiftool -time:all -a -G0:1 -s a.mp4
[File:System]   FileModifyDate                  : 2013:04:28 09:35:16+12:00
[File:System]   FileAccessDate                  : 2013:04:29 14:06:03+12:00
[File:System]   FileCreateDate                  : 2013:04:29 14:06:03+12:00
[QuickTime]     CreateDate                      : 2013:04:20 01:28:07
[QuickTime]     ModifyDate                      : 2013:04:20 01:28:07
[QuickTime:Track1] TrackCreateDate              : 2013:04:20 01:28:07
[QuickTime:Track1] TrackModifyDate              : 2013:04:20 01:28:07
[QuickTime:Track1] MediaCreateDate              : 2013:04:20 01:28:07
[QuickTime:Track1] MediaModifyDate              : 2013:04:20 01:28:07
[QuickTime:Track2] TrackCreateDate              : 2013:04:20 01:28:07
[QuickTime:Track2] TrackModifyDate              : 2013:04:20 01:28:07
[QuickTime:Track2] MediaCreateDate              : 2013:04:20 01:28:07
[QuickTime:Track2] MediaModifyDate              : 2013:04:20 01:28:07

D:\temp\vids\x>exiftool "-FileCreateDate<CreateDate" "-FileModifyDate<CreateDate" a.mp4
    1 image files updated

Joseph Allan

Hi.  I am now trying to run this on a directory, but I keep getting "0 image files read".  It works fine if I enter in a single .mp4 file but does not pick them up if using the -r option.

D:\temp\vids\x>exiftool "-FileCreateDate<CreateDate" "-FileModifyDate<CreateDate" -r D:\temp\vids\x\Camera
    1 directories scanned
    0 image files read


And the single file...

D:\temp\vids\x>exiftool "-FileCreateDate<CreateDate" "-FileModifyDate<CreateDate" D:\temp\vids\x\Camera\20130330_180321.mp4
    1 image files updated


What am I doing wrong? Thanks.

Joseph Allan

Ok... Worked it out. Need to specify the file extension.

D:\>exiftool "-FileCreateDate<CreateDate" "-FileModifyDate<CreateDate" -ext .mp4 -r D:\temp\vids\x\Camera
    1 directories scanned
   11 image files updated


The default is to process only supported files, but changing the file creation and modify dates do not change the files themselves - so should be ok with video files.  Is that right?

Phil Harvey

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

airdrummer

i recently replaced my dead flipphone w/ an LG  ( i'm cheap; i'll get an iphone when my daughter upgrades to a 5;-) it's a real p.o.s.: not only are the filenames in mmddyyyy format off by 10 years(hey the phone isn't_that_old)-:

> ls -l 0818031904a.jpg
-rwxrwxrwx  1 tomw  admin  539476 Aug 18 23:04 0818031904a.jpg

but the stored exif dates are in a non-standard format:

> exiftool -FileModifyDate -DateTimeOriginal 0818031904a.jpg
File Modification Date/Time  : 2013:08:18 23:04:16-04:00
Date/Time Original              : 08.18.2013 19:04:15

which of course means this fails:

> exiftool "-FileModifyDate<DateTimeOriginal" 0818031904a.jpg
Warning: Month '18' out of range 0..11 in File:FileModifyDate (ValueConvInv) - 0818031904a.jpg
Warning: No writable tags set from 0818031904a.jpg
    0 image files updated
    1 image files unchanged

the -d FMT, -dateFormat is for output only, right? so do i have to extract/parse/reset the exif date in a 3-step shell process, or is there some way exiftool can do it in 1 swell foop?-)

StarGeek

I just used the following command to fix your date/time original problem:
exiftool "-datetimeoriginal<${datetimeoriginal;s/(\d{2})\.(\d{2})\.(\d{4}) (.*)/$3:$1:$2 $4/}" <file or dir>

but it also threw a Warning: [minor] Entries in IFD0 were out of sequence. Fixed., so maybe there's some other problems with the file.

Also, CreateDate suffers from the same date ordering problem, so you might want to fix that as well.  To do it all in one shot:
exiftool "-DateTimeOriginal<${DateTimeOriginal;s/(\d{2})\.(\d{2})\.(\d{4}) (.*)/$3:$1:$2 $4/}" "-CreateDate<${CreateDate;s/(\d{2})\.(\d{2})\.(\d{4}) (.*)/$3:$1:$2 $4/}"  "-FileModifyDate<${DateTimeOriginal;s/(\d{2})\.(\d{2})\.(\d{4}) (.*)/$3:$1:$2 $4/}"  <file or dir>

Make sure and test it first, seemed to work fine here.

Edit: Added FileModifyDate to final command
Edit 2: Fixed derp moment on substitution ordering, now it should be correct
* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).

airdrummer

#8
i wasn't familiar w/the <${srcTag;s/regex/regex/} construct...if it's in phil's docs somewhere i musta skimmed right past it...the downside of reams of docs;-)

d'oh!-( what shell? just tried both omm:

> exiftool "-datetimeoriginal<${datetimeoriginal;s/(\d{2})\.(\d{2})\.(\d{4}) (.*)/$3:$1:$2 $4/}" 0818031904a.jpg
-bash: -datetimeoriginal<${datetimeoriginal;s/(\d{2})\.(\d{2})\.(\d{4}) (.*)/$3:$1:$2 $4/}: bad substitution
> exiftool -ver9.35
> uname -a
Darwin toms-MacBook-Pro.local 11.4.2 Darwin Kernel Version 11.4.2: Thu Aug 23 16:25:48 PDT 2012; root:xnu-1699.32.7~1/RELEASE_X86_64 x86_64



Phil Harvey

Use single quotes on Mac/Linux, not double quotes.  bash interpolates variables (starting with a "$") inside double quotes.

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

StarGeek

Sorry, bad assumption on my part, passed right over where you used ls for the directory listing.  I use windows which uses double quotes.  For mac/linux, use single quotes.  Try this?

exiftool '-DateTimeOriginal<${DateTimeOriginal;s/(\d{2})\.(\d{2})\.(\d{4}) (.*)/$3:$1:$2 $4/}' '-CreateDate<${CreateDate;s/(\d{2})\.(\d{2})\.(\d{4}) (.*)/$3:$1:$2 $4/}' '-FileModifyDate<${DateTimeOriginal;s/(\d{2})\.(\d{2})\.(\d{4}) (.*)/$3:$1:$2 $4/}' <file or dir>

As for the docs, you'll find it under the -p FMTFILE or STR (-printFormat) section (look for the "advanced formatting" line).
* Did you read FAQ #3 and use the command listed there?
* Please use the Code button for exiftool code/output.
 
* Please include your OS, Exiftool version, and type of file you're processing (MP4, JPG, etc).

airdrummer

d'oh! didn't even think about the quotes...i've spent the last week banging on mysql, which doesn't care, and bash does...i knew that2 weks ago;-}

thanx v.much 4 ur help...th'intarwebs'll save me from my crss/ol'timer's!-)

dld44

I'm resurrecting this topic because it is similar to what I want to do.

I have a couple thousand mostly very old scanned photos that I have been putting together in Photoshop Elements Organizer over the last 10-12 years. I set the date of the original photo with Organizer's Date and Time tag, which stores in the DateTimeOriginal EXIF tag. Organizer allows addition of a partial date, e.g., year only, in which case the remainder or blank portion of the input is set as 00s in the DateTimeOriginal tag. I typically select these photos by keyword tags and view them in Date order. I am readying the jpgs for viewing online, and also need to be able to sort the files by this original photo date in this environment.

It would be a simple matter of updating the FileCreateDate and/or FileModifyDate to match the DateTimeOriginal  tag. But when I attempt to do this, ExifTool sees the zeros in the DateTimeOriginal tag as invalid, and the operation aborts with an error. (I can successfully use another ExifTool function to rename the file with the date at the beginning, but the date ends up incorrect. For example, a DateTimeOriginal date of 1912, no month, day, etc., would end up as 1911-11-01.)

What I am looking for is some ideas about how to solve this. I would like to use as much of the date as is in the tag, perhaps padding the remainder with some false additional components, (e.g. this 1912 may become 1912-01-01), or whatever might be possible with ExifTool.

Ideas?
DaveD

Phil Harvey

Hi Dave,

Would it do what you want to replace a month/day of "00:00" with "01:01"?  If so, try this:

exiftool "-filemodifydate<${datetimeoriginal;s/(\d{4}):00:00/$1:01:01/}" FILE

where FILE is one or more directory and/or file names.  Use single quotes instead of double if you are on Mac or Linux.

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

dld44

Hi Phil, thanks for the quick response.

That would work, but only for those situations where only the year is filled in, as I read it. In many cases I have a month and day, sometimes a time. Since I need to batch process, it would have to work in all cases. Perhaps I could read the data into a file, post-process it, and then write the results back. But that would be difficult with my limited experience with your tool. BTW, I am using the ExifToolGUI, but through its command line, if that makes a difference.
DaveD