Created
January 3, 2012 18:17
-
-
Save danhixon/1556154 to your computer and use it in GitHub Desktop.
create yyyy-mm folders for your photos
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
# Depends on the command line tool: exiftool | |
# brew install exiftool | |
# it also works with mov files if they have | |
# exif data. I know my iPhone adds the exif | |
photos = Dir.glob("*.jpg",File::FNM_CASEFOLD) | |
photos.each do |file_path| | |
file_path = file_path.gsub(' ','\ ') | |
puts file_path | |
date = `exiftool #{file_path} | grep "Create Date"` | |
puts "no creation date for #{file_path}" && next if date.chomp == "" | |
year, month, day = date.chomp.split(": ").last.split(" ").first.split(":") | |
folder_name = "#{year}-#{month}" | |
`mkdir #{folder_name}` unless Dir::exists?(folder_name) | |
`mv #{file_path} #{folder_name}/#{file_path}` | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment