Skip to content

Instantly share code, notes, and snippets.

@ernestas-poskus
Created December 21, 2014 20:12
Show Gist options
  • Save ernestas-poskus/1d77bfc971eccc660669 to your computer and use it in GitHub Desktop.
Save ernestas-poskus/1d77bfc971eccc660669 to your computer and use it in GitHub Desktop.
Image sorter for Dropbox
# Image sorter for Dropbox
require 'fileutils'
path = ARGV[1] || '.'
Dir.entries(path).each do |file|
m = file.scan(/^(\d{4})-(\d{2})-(\d{2}).+\.(jpg|jpeg|png|gif|mp4)/).flatten
# If file extension exists then is photo/video
if(!m[3].nil?)
# Dir path - ./2014/2014-07-05
dir = File.join(Dir.pwd, "#{m[0]}", "#{m[0]}-#{m[1]}-#{m[2]}")
FileUtils.mkdir_p(dir) unless File.exists?(dir)
if(ARGV[0] == 'cp')
FileUtils.cp(file, dir)
else
FileUtils.mv(file, dir)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment