Skip to content

Instantly share code, notes, and snippets.

@onodes
Created August 1, 2010 15:15
Show Gist options
  • Save onodes/503455 to your computer and use it in GitHub Desktop.
Save onodes/503455 to your computer and use it in GitHub Desktop.
require 'rubygems'
require 'mini_exiftool'
require 'pp'
dir = ARGV[0].chomp
file_array = Dir::glob(dir + "*.{jpg,JPG,NEF}")
file_instance = file_array.map{|filename| MiniExiftool.new(filename) }
puts "file scan"
file_date_array = file_instance.map{|file| file.DateTimeOriginal}
puts 'get file DateTime'
file_date_array.map!{|filename| filename.strftime("%Y") + filename.strftime("%m") + filename.strftime("%d")}.uniq!
file_date_array.each{|dir_name|
p dir_name
begin
Dir.mkdir(dir + dir_name)
rescue
next
end
}
puts "create directory"
file_instance.each{|file|
# p file
begin
File.rename(file.filename,file.directory + "/" + file.DateTimeOriginal.strftime("%Y%m%d")+"/"+File.basename(file.filename))
rescue
next
end
}
puts "Finish! your require that file move"
#pp file_instance[0]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment