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 (https://exiftool.org/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
Quote from: StarGeek on May 28, 2017, 05:26:30 PM
Do it all in exiftool. 

exiftool "-FileModifyDate<DateTimeOriginal" FileOrDir

Works great, thanks!
Title: Re: Update file timestamp with exif timestamp
Post by: username on September 24, 2024, 02:23:21 PM
Hi all,

I'm also in need of changing some timestamps. I have 200+ pictures where the timestamps are wrong.
I assume this occurred because there was no battery in the camera for quite some time and now the dates are "31 days, 15 hours, and 46 minutes" (2,735,160 seconds) off.

I checked the EXIF information, and it looks like the wrong dates are stored in these fields:

Is there a way to simply shift all these dates?

Thanks in advance.
Title: Re: Update file timestamp with exif timestamp
Post by: StarGeek on September 24, 2024, 03:05:19 PM
The -TAG[+-^]=[VALUE] option (https://exiftool.org/exiftool_pod.html#TAG---VALUE) and the ExifTool Date/Time Shift Module (https://exiftool.org/Shift.html) have the details on shifting time stamps.

To shift timestamps, the command would be
exiftool -TAG±="Year:Month:Day Hour:Minute:Second" /path/to/files/
Where you would replace ± with the proper sign to add or subtract. You can drop leading/trailing values that are 0.

Most of those tags can be covered with this command, assuming you're adding days/hours/minutes. AllDates is a shortcut for the three most common EXIF timestamps, CreateDate, DateTimeOriginal, and ModifyDate.
exiftool -Alldates+="31 15:46" -FileCreateDate+="31 15:46" -FileModifyDate+="31 15:46" /path/to/files/

Use this command to make sure of the correct name of "TimeStamp". Depending upon the camera it came from, it may not be editable. For example, I think it won't be editable if it's from a Samsung phone.
exiftool -time:all -G1 -a -s /path/to/files/

Once you figure out what it is, you can either add it to the above command or run it separately.
Title: Re: Update file timestamp with exif timestamp
Post by: username on September 24, 2024, 04:12:55 PM
Thanks a lot. It worked like a charm.

I have a Panasonic TZ101.

What is your second command for "exiftool -time:all -G1 -a -s /path/to/files/", this I didn't get?
Title: Re: Update file timestamp with exif timestamp
Post by: StarGeek on September 25, 2024, 09:51:22 AM
Quote from: username on September 24, 2024, 04:12:55 PMWhat is your second command for "exiftool -time:all -G1 -a -s /path/to/files/", this I didn't get?

You would use that to find the actual tag name for "Time Stamp". It is most likely TimeStamp but it may not be. You would use that name instead of "TAG" in the above commands, either running it separately or by adding it to the longer command.