Skip to content

Instantly share code, notes, and snippets.

@akwiatkowski
Created February 10, 2020 10:07
Show Gist options
  • Save akwiatkowski/9c11c74b7c139d3de909a94b831944ca to your computer and use it in GitHub Desktop.
Save akwiatkowski/9c11c74b7c139d3de909a94b831944ca to your computer and use it in GitHub Desktop.
draft script for mass exif (and filename) time update: change year
require "time"
Dir.new(".").each do |f|
next unless f =~ /jpg/i
command = "exiftool -T -createdate '#{f}'"
puts command
result = `#{command}`
time_string = "#{result}"
time_string[4] = "-"
time_string[7] = "-"
time = Time.parse(time_string)
puts "parsed #{time}"
if time.year < 2020
new_time = Time.new(
2020,
time.month,
time.day,
time.hour,
time.min,
time.sec
)
puts "new time #{new_time}"
update_command = "exiftool -AllDates='#{new_time.year}:#{new_time.month}:#{new_time.day} #{new_time.hour}:#{new_time.min}:#{new_time.sec}' '#{f}'"
puts update_command
`#{update_command}`
end
unless f =~ /2020.+/i
puts "need to update filename"
new_filename = f.clone
new_filename[2] = '2'
new_filename[3] = '0'
rename_command = "mv '#{f}' '#{new_filename}'"
puts rename_command
`#{rename_command}`
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment