Update file timestamp with exif timestamp

Started by jf, November 24, 2012, 10:30:08 AM

Previous topic - Next topic

jf

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




jf

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.

Phil Harvey

Hi,

1) See the strftime manpage for your system to see what date/time format codes are available.  I list the common ones here.

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

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

jf

#3
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

bobbozzo

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!

bobbozzo

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!

StarGeek

Do it all in exiftool. 

exiftool "-FileModifyDate<DateTimeOriginal" FileOrDir

"It didn't work" isn't helpful. What was the exact command used and the output.
Read FAQ #3 and use that cmd
Please use the Code button for exiftool output

Please include your OS/Exiftool version/filetype

bobbozzo

Quote from: StarGeek on May 28, 2017, 05:26:30 PM
Do it all in exiftool. 

exiftool "-FileModifyDate<DateTimeOriginal" FileOrDir

Works great, thanks!

username

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:
  • File Modification Date/Time
  • Time Stamp
  • Create Date
  • Date/Time Original
  • Modify Date

Is there a way to simply shift all these dates?

Thanks in advance.

StarGeek

The -TAG[+-^]=[VALUE] option and the ExifTool Date/Time Shift Module 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.
"It didn't work" isn't helpful. What was the exact command used and the output.
Read FAQ #3 and use that cmd
Please use the Code button for exiftool output

Please include your OS/Exiftool version/filetype

username

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?

StarGeek

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.
"It didn't work" isn't helpful. What was the exact command used and the output.
Read FAQ #3 and use that cmd
Please use the Code button for exiftool output

Please include your OS/Exiftool version/filetype