diff --git a/movefromexif.rb b/movefromexif.rb new file mode 100644 index 0000000..d852dea --- /dev/null +++ b/movefromexif.rb @@ -0,0 +1,44 @@ +#!/usr/bin/env ruby + +# == Summary +# Moves JPEG files from directory to another creating a year/month/day structure +# +# == Usage +# ./movefromexif.rb [source_folder] [destination_folder] +# +# == Version History +# v0.0.1 - 2011/02/10 +# +# == Issues +# None known + +require 'rubygems' +require 'mini_exiftool' +require 'fileutils' + +class MoveFromExif + def self.sort(source, target) + MoveFromExif.get_images(source).each do |filename| + photo = MiniExiftool.new filename + time = photo.date_time_original + destination = File.join(target, time.year.to_s, "%02d" % time.month, "%02d" % time.day) + if File.dirname(filename) != destination + FileUtils.makedirs(destination) unless File.exists? destination + FileUtils.mv(filename, destination) + puts "Moved #{filename} to #{destination}" + end + end + end + + private + def self.get_images(directory) + Dir.glob(File.join(directory,'**','*.jpg'), File::FNM_CASEFOLD) + end +end + +if ARGV.size != 2 + puts "Usage: movefromexif source_folder target_folder" + exit -1 +else + MoveFromExif.sort(ARGV[0],ARGV[1]) +end \ No newline at end of file