Browse Source

Add ruby script

master
djib 6 months ago
parent
commit
ad0e679965
1 changed files with 44 additions and 0 deletions
  1. +44
    -0
      movefromexif.rb

+ 44
- 0
movefromexif.rb View File

@@ -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

Loading…
Cancel
Save