Browse Source

Add ruby script

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

Loading…
Cancel
Save