Skip to content

Instantly share code, notes, and snippets.

@capotej
Created June 10, 2010 18:52
Show Gist options
  • Save capotej/433453 to your computer and use it in GitHub Desktop.
Save capotej/433453 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
require 'ftools'
EXTS = %w{ jpg gif jpeg png }
DEST = '/Users/capotej/Pictures'
def cleanup?(p)
return true unless EXTS.select { |f| p.to_s.include?(f) or p.to_s.include?(f.upcase) }.empty?
end
Dir["/Users/capotej/Desktop/*"].each do |p|
if cleanup?(p)
unless File.exists?(DEST + '/' + File.basename(p))
File.move(p, DEST)
else
new_name = p + ".dup#{rand(123123)}"
File.rename(p, new_name)
File.move(new_name, DEST)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment