ExifTool Forum

ExifTool => Newbies => Topic started by: jf on November 24, 2012, 10:30:08 AM

Title: Update file timestamp with exif timestamp
Post by: jf on November 24, 2012, 10:30:08 AM
Hi there,

First of all, I would like to thank Phil Harvey for writing this wonderful tool!

I'm just starting to use it, and right now, my objective is simple:

1. Reorganize my directory and file structure so that it is in the form %Y/%m/%d/%Y%m%d_%H%M%S%%-c.%%e and I use this command to do it...


     exiftool -progress -r -d %Y/%m/%d/%Y%m%d_%H%M%S%%-c.%%e "-filename<CreateDate" <source_directory>


   ... and this part works as I expected.

   But is it possible to do it so that I also have the literal month & day of week, like: 2012/11Nov/24Sat ?

2. I want to set the file's timestamp to be the same as the CreateDate, and I got this piece of code somewhere from the internet...


    find . -type f | while read PIC; do
      exiftool -S -d "%Y%m%d%H%M.%S" -CreateDate "${PIC}" \
      | awk '{ print $2 }' \
      | xargs -I % touch -m -t % "${PIC}"
    done


   ... and this one also works.  But I find this slow, perhaps because exiftool is instantiated for every file (I'm processing more than 50,000 files).

So my question is: What is the most efficient way to do objective #2?  Can exiftool itself change the file's timestamp?  Can #1 & #2 be done in a single command?

In case it matters, my environment is:
- Mac OS X 10.7.5
- exiftool 9.07
- files being processed are mostly JPG & DNG files.

TIA,

-jf



Title: Re: Update file timestamp with exif timestamp
Post by: jf on November 24, 2012, 01:57:56 PM
I think I can do this for #2:


    exiftool -r -q -d "%Y%m%d%H%M.%S" -p '$dateTimeOriginal $directory/$filename'  . | xargs -t -n2 touch -m -t


It is much faster than the find/while loop.
Title: Re: Update file timestamp with exif timestamp
Post by: Phil Harvey on November 24, 2012, 02:18:22 PM
Hi,

1) See the strftime manpage for your system to see what date/time format codes are available.  I list the common ones here (http://owl.phy.queensu.ca/~phil/exiftool/filename.html).

2) Unix-type hackers really like to pipe stuff through awk, but 90% of the time you can do it more easily with exiftool options.  In this case, just add "-filemodifydate<createdate#" to your first command to also set the filesystem modification date/time.  The only trick here is that in this case you don't want to copy the formatted (-d) date/time, so the trailing "#" is used to get the unformatted value.

- Phil

Title: Re: Update file timestamp with exif timestamp
Post by: jf on November 24, 2012, 04:31:03 PM
Hi Phil,

Thank you very much for the fast reply.

I did what you suggested and I got to do everything I wanted in a single command, using only exiftools...


   exiftool -progress -r -d %Y/%m%b/%d%a/%Y%m%d_%H%M%S%%-c.%%e "-filename<createdate" "-filemodifydate<createdate#" <source_directory>


... and this single command is roughly 40 times faster than what I mentioned in the initial post - this is exactly the result I was hoping to get.

Again, thank you very much for the wonderful software and excellent forum.

-jf
Title: Re: Update file timestamp with exif timestamp
Post by: bobbozzo on May 28, 2017, 04:46:33 PM
Hi, I need to correct some damaged file timestamps (#2 in the OP - set the file's timestamp to be the same as the CreateDate)

exiftool -r -q -d "%Y%m%d%H%M.%S" -p '$dateTimeOriginal $directory/$filename'  . | xargs -t -n2 touch -m -t
but this gives me errors on Windows (I do have xargs and touch installed from gnuwin32 tools)

t:\Temp>exiftool -r -q -d "%Y%m%d%H%M.%S" -p '$dateTimeOriginal $directory/$filename'  . | xargs -t -n2 touch -m -t
File not found: $directory/$filename'
xargs: unmatched single quote; by default quotes are special to xargs unless you use the -0 option

t:\Temp>exiftool -r -q -d "%Y%m%d%H%M.%S" -p '$dateTimeOriginal $directory/$filename'  * | xargs -t -n2 touch -m -t
File not found: $directory/$filename'
xargs: unmatched single quote; by default quotes are special to xargs unless you use the -0 option


Thanks!
Title: Re: Update file timestamp with exif timestamp
Post by: bobbozzo on May 28, 2017, 04:49:19 PM
It works on Windows by using double quotes:
exiftool -r -q -d "%Y%m%d%H%M.%S" -p "$dateTimeOriginal $directory/$filename"  . | xargs -t -n2 touch -m -t

However it does not work if there are spaces in the filenames; touch gets an error as it's thinking the spaces are parameter separators.
How can I pass those parameters quoted, or do it all in exiftool without xargs?

Thanks!
Title: Re: Update file timestamp with exif timestamp
Post by: StarGeek on May 28, 2017, 05:26:30 PM
Do it all in exiftool. 

exiftool "-FileModifyDate<DateTimeOriginal" FileOrDir

Title: Re: Update file timestamp with exif timestamp
Post by: bobbozzo on May 28, 2017, 07:33:02 PM
Do it all in exiftool. 

exiftool "-FileModifyDate<DateTimeOriginal" FileOrDir

Works great, thanks!