Last active
July 15, 2017 21:11
-
-
Save diasjorge/4b1821848deac36db3ab3a5fac82712a to your computer and use it in GitHub Desktop.
Album fixes
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 'fileutils' | |
require 'date' | |
# Sort by date taken | |
pics = Dir.glob('*.jpg', File::FNM_CASEFOLD) | |
sorted_pics = pics.sort_by do |f| | |
%x{identify -format "%[EXIF:DateTime]" "#{f}"} | |
end | |
# Rename by sorted order | |
sorted_pics.each_with_index do |f, i| | |
FileUtils.mv(f, "#{i}.jpg") | |
end | |
# Change modified date according to order | |
pics = Dir.glob('*.jpg', File::FNM_CASEFOLD) | |
pics.each_with_index do |f,i| | |
FileUtils.touch f, mtime: Time.now + i | |
end | |
# Change modified date according to order | |
pics = Dir.glob('*.jpg', File::FNM_CASEFOLD) | |
size = pics.sort_by(&:length).last.split(".").first.size | |
pics.each do |f| | |
name = File.basename(f, File.extname(f)) | |
if name.length < size | |
(size - name.length).times do | |
name = name.prepend('0') | |
end | |
FileUtils.mv(f, "#{name}.jpg") | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment