Skip to content

Instantly share code, notes, and snippets.

@thejspr
Created January 8, 2016 22:13
Show Gist options
  • Save thejspr/8cc83e5cccf17cc11af0 to your computer and use it in GitHub Desktop.
Save thejspr/8cc83e5cccf17cc11af0 to your computer and use it in GitHub Desktop.
Set exif dates on images based on their filename
require 'time'
# Files with a name like "2010-12-08 12.34.20.png" gets their
# exif dates set to that time.
files = Dir.glob('*.*g')
files.each do |file|
date = file.to_s[0...file.to_s.length-4]
time = Time.parse(date.gsub('.', ':'))
formatted_date = time.strftime("%Y:%m:%d %H:%M:%S")
cmd = "exiftool -AllDates='#{formatted_date}' -overwrite_original '#{file}'"
system(cmd)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment