3

I have more than 800 pictures where I need to extract the date of creation. But if I use the file.mtime function, it's not working. It's just the date that I modified it. The funny thing is that iPhoto (a program on mac to manage photos) is able to detect the date of creation properly.

This is the code I was using.

my.path = "~/Desktop/cool_path_here"
vec.jpg = list.files(path = my.path)
lapply(paste(my.path,vec.jpg,sep = "/"),FUN =  file.mtime)

Is there a function that could extract the date of creation of the photo and not the one that is shown in the "get info" menu on mac.

e.g.: (yesterday was May 18th)

enter image description here

and in iPhoto (found March 16th):

enter image description here

R is finding:

2017-05-19 15:08:29
M. Beausoleil
  • 3,141
  • 6
  • 29
  • 61

2 Answers2

6

Use the exif package to extract the metadata:

library(exif)
read_exif(paste(my.path,vec.jpg[1], sep="/"))$origin_timestamp

is returning "2017:03:16 08:47:48" which is the what I was looking for!

M. Beausoleil
  • 3,141
  • 6
  • 29
  • 61
1

As per ?file.info, mtime is the modification time, ctime is the "last status change" time, and atime is the last "access" time. According to here, the POSIX standard (which Mac OS follows) does not include a creation time among the standard properties of a file.

file.info(my.path)$atime may be better. That didn't change in this test:

DF = data.frame(a = 1:10, b = 10:1)
tmp = tempfile()
write.table(DF, tmp)
Sys.time()
# [1] "2017-05-19 15:03:46 EDT"
file.info(tmp)[ , c('mtime', 'ctime', 'atime')]
#                                                mtime               ctime               atime
# /tmp/Rtmpzpi8p6/file29e932565c62 2017-05-19 15:03:46 2017-05-19 15:03:46 2017-05-19 15:03:46
DF$c = 11:20
Sys.sleep(10)
write.table(DF, tmp)
file.info(tmp)[ , c('mtime', 'ctime', 'atime')]
#                                                mtime               ctime               atime
# /tmp/Rtmpzpi8p6/file29e932565c62 2017-05-19 15:03:56 2017-05-19 15:03:56 2017-05-19 15:03:4

BTW, use the full.names argument to list.files instead of using paste and sep='/'.

Community
  • 1
  • 1
MichaelChirico
  • 33,841
  • 14
  • 113
  • 198
  • I've tried this, but it's not working. I meant, there is other metadata in the jpeg that this function is not able to extract. I wonder if there is a way to extract that metadata in R. iPhoto is able to do it, so I guess R should be... – M. Beausoleil May 19 '17 at 19:07
  • @M.Beausoleil you'll have to provide some reproducible example – MichaelChirico May 19 '17 at 19:09
  • I'd like to but can't really share the pictures in question. But for sure, there is an information that file.info is not getting and that iPhoto is able to reach. – M. Beausoleil May 19 '17 at 19:12
  • @M.Beausoleil you don't necessarily need to share the pictures in question. Just mock up some files that you _can_ share, or even use Google. – MichaelChirico May 19 '17 at 19:12
  • @M.Beausoleil does this package work? https://cran.r-project.org/web/packages/exif/exif.pdf – MichaelChirico May 19 '17 at 19:21
  • Yes, it's doing what I'm looking for, and it extracts a lot more information. See my answer. – M. Beausoleil May 19 '17 at 19:35