lib/photoarchiver.rb in photoarchiver-0.1.1 vs lib/photoarchiver.rb in photoarchiver-0.1.3

- old
+ new

@@ -17,18 +17,21 @@ end puts "Source Directory: #{dir_src}" puts "Target Directory: #{dir_target}" + # Gather up all the potential photo files - photos = Dir.glob(File.join(dir_src, '**', '*.jpg')).reject { |temp| File.directory? temp } + files = Dir.glob(File.join(dir_src, '**', '*')).reject { |temp| File.directory? temp } + photos = files.grep(/\.JPG/i) # Loop through the photos, not currently using index but may in the future photos.each_with_index {|val, index| - exif_data = EXIFR::JPEG.new(val).date_time_original - FileUtils::mkdir_p File.join(dir_target, exif_data.strftime('%Y'), exif_data.strftime('%Y-%m-%d')) - target_file = File.join(dir_target, exif_data.strftime('%Y'), exif_data.strftime('%Y-%m-%d'), exif_data.strftime('%Y%m%d-%H%M%S')) + '.jpg' + date_created = EXIFR::JPEG.new(val).exif.date_time_original || File.stat(val).ctime + + FileUtils::mkdir_p File.join(dir_target, date_created.strftime('%Y'), date_created.strftime('%Y-%m-%d')) + target_file = File.join(dir_target, date_created.strftime('%Y'), date_created.strftime('%Y-%m-%d'), date_created.strftime('%Y%m%d-%H%M%S')) + '.jpg' puts "Moving #{val} to #{target_file}" File.rename(val, target_file) } puts 'Done processing photos' end \ No newline at end of file