Skip to content

Instantly share code, notes, and snippets.

@javascripter
Created August 29, 2009 06:45
Embed
What would you like to do?
#!/usr/bin/env ruby
# vim: ft=ruby
def mk_uniq_name_by(filename, path)
uniq_name = filename
prefix = 0
while FileTest.exist?(File.join(path, uniq_name))
prefix += 1
uniq_name = sprintf("%d.%s", prefix, filename)
end
uniq_name
end
def die(*args)
$stderr.printf(*args)
exit(1)
end
def trash(filename)
die("No such file or directory: %s\n", filename) unless FileTest.exist?(filename)
trash_path = File.expand_path("~/.Trash")
basename = File.basename(filename)
newname = mk_uniq_name_by(basename, trash_path)
File.rename(filename, File.join(trash_path, newname))
end
ARGV.each {|filename|
trash(filename)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment