Module: CmdTools::Command::Trash
- Extended by:
- RubyPatch::AutoLoad
- Defined in:
- lib/cmd_tools/command/trash.rb
Constant Summary collapse
- TRASH_DIR =
File.join(ENV['HOME'], '.myTrash')
Class Method Summary collapse
-
.run(*files) ⇒ Object
Move files and directories into
TRASH_DIR
.
Class Method Details
.run(*files) ⇒ Object
Move files and directories into TRASH_DIR
.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/cmd_tools/command/trash.rb', line 10 def self.run(*files) FileUtils.mkdir_p(TRASH_DIR) time = Time.now.ymdhms prefix = File.join(TRASH_DIR, time) + '.' (files.flatten - ['.', '..'])\ .select{|f| File.exist?(f) || File.symlink?(f)}\ .each{|f| begin FileUtils.mv(f, prefix + File.basename(f)) rescue warn "WARN: Failed to discard #{f}" end } end |