Created
May 28, 2018 18:04
-
-
Save Jon-Schneider/f48343b44192fec2a75f4a72520d862c to your computer and use it in GitHub Desktop.
Fix Creation and Update Dates
This file contains 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
# 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