Created
March 5, 2009 20:30
-
-
Save jonmagic/74542 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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