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.

movefromexif.rb 1.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. #!/usr/bin/env ruby
  2. # == Summary
  3. # Moves JPEG files from directory to another creating a year/month/day structure
  4. #
  5. # == Usage
  6. # ./movefromexif.rb [source_folder] [destination_folder]
  7. #
  8. # == Version History
  9. # v0.0.1 - 2011/02/10
  10. #
  11. # == Issues
  12. # None known
  13. require 'rubygems'
  14. require 'mini_exiftool'
  15. require 'fileutils'
  16. class MoveFromExif
  17. def self.sort(source, target)
  18. MoveFromExif.get_images(source).each do |filename|
  19. photo = MiniExiftool.new filename
  20. time = photo.date_time_original
  21. destination = File.join(target, time.year.to_s, "%02d" % time.month, "%02d" % time.day)
  22. if File.dirname(filename) != destination
  23. FileUtils.makedirs(destination) unless File.exists? destination
  24. FileUtils.mv(filename, destination)
  25. puts "Moved #{filename} to #{destination}"
  26. end
  27. end
  28. end
  29. private
  30. def self.get_images(directory)
  31. Dir.glob(File.join(directory,'**','*.jpg'), File::FNM_CASEFOLD)
  32. end
  33. end
  34. if ARGV.size != 2
  35. puts "Usage: movefromexif source_folder target_folder"
  36. exit -1
  37. else
  38. MoveFromExif.sort(ARGV[0],ARGV[1])
  39. end