Skip to content

Instantly share code, notes, and snippets.

@jonmagic
Created March 5, 2009 20:30
Show Gist options
  • Save jonmagic/74542 to your computer and use it in GitHub Desktop.
Save jonmagic/74542 to your computer and use it in GitHub Desktop.
#!/usr/local/bin/ruby
require 'ftools'
class String
def has(word)
self =~ /#{word}/ ? true : false
end
def suffix(n)
return self if n == 1
case self
when /n$/
"#{self}s"
when /y$/
"#{self[0...-1]}s"
else
self # don't know what to do about this ending
end
end
end
filename = "#{ARGV}"
count = 0
File.open(filename, "r") do |file|
while (line = file.gets)
if line.has("Users") && File.exist?(line.gsub("\r\n", ""))
puts "Moving '#{line.gsub("\r\n", "")}' to the Trash\n"
File.move line.gsub("\r\n", ""), "#{ENV["HOME"]}/.Trash/"
count += 1
end
end
end
puts "Moved #{count} #{'file'.suffix(count)} to the trash, Process Complete!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment