Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Jon-Schneider/f48343b44192fec2a75f4a72520d862c to your computer and use it in GitHub Desktop.
Save Jon-Schneider/f48343b44192fec2a75f4a72520d862c to your computer and use it in GitHub Desktop.
Fix Creation and Update Dates
# A quick and dirty ruby script to update the creation and modified date of files.
# I use it before uploading to Google Photos.
# Just drop it into the directory your files are in.
# Currently based on the format '2016-08-20_21-54-44_000.ext' but this can be modified'
Dir.foreach('.') do |item|
next if item == '.' or item[0] == "." or item == '..' or item == "update_times.rb"
dateAndTime = item.split('_')
date = dateAndTime[0].split('-')
time = dateAndTime[1].split('-')
creationDate = Time.new(date[0].to_i, date[1].to_i, date[2].to_i, time[0].to_i, time[1].to_i, time[2].to_i, "-05:00")
puts creationDate
File.utime(creationDate, creationDate, item)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment