Skip to content

Instantly share code, notes, and snippets.

@danhixon
Created January 3, 2012 18:17
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save danhixon/1556154 to your computer and use it in GitHub Desktop.
Save danhixon/1556154 to your computer and use it in GitHub Desktop.
create yyyy-mm folders for your photos
# 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