Created
February 10, 2020 10:07
-
-
Save akwiatkowski/9c11c74b7c139d3de909a94b831944ca to your computer and use it in GitHub Desktop.
draft script for mass exif (and filename) time update: change year
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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