Module: Rpa::Util

Extended by:
Util
Included in:
Util
Defined in:
lib/rpa/util.rb

Instance Method Summary collapse

Instance Method Details

#get_file_creation_time(path) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/rpa/util.rb', line 7

def get_file_creation_time(path)
  ext = File.extname(path)
  t = if m = ext.downcase.match(/(tiff|tif|jpg|jpeg)$/)
    exif_class = m[1][0] == 't' ? EXIFR::TIFF : EXIFR::JPEG
    begin
      exif = exif_class.new(path)
      exif.date_time ||
        exif.date_time_original ||
        exif.date_time_digitized
    rescue => e
      STDERR.puts "Error getting EXIF data for #{path}: #{e.message}"
    end
  end
  t ||= File::Stat.new(path).ctime
end