A simple Ruby script to move JPEG from a directory to another creating a year/month/day structure
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

44 lines
1.1 KiB

#!/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