Mark Hubbart
12/23/2004 7:54:00 AM
On Thu, 23 Dec 2004 13:12:17 +0900, trans. (T. Onoma)
<transami@runbox.com> wrote:
> Hmm. I thought for sure -f overwrote, but indeed you are right. So that means
> one must perform a 'rm -r' first? If so that's really bad, as it is a much
> more dangerous way to have to go about it. If the wrong directory name got in
> there it could spell the end of one's machine :( Is there no way to simply
> (and truly) _force_ a move?
It's time to roll your own. If you don't have to worry about moving
across filesystems, a simple File.rename will work:
irb(main):001:0> Dir.mkdir ".trash"
=> 0
irb(main):002:0> Dir.mkdir "aaa"
=> 0
irb(main):003:0> Dir.mkdir ".trash/aaa"
=> 0
irb(main):004:0> Dir.mkdir "aaa/foo"
=> 0
irb(main):005:0> File.rename "./aaa", "./.trash/aaa"
=> 0
irb(main):012:0> puts Dir['.trash/**/*']
trash/aaa
trash/aaa/foo
If you attempt a move across filesystems, rename should raise an
error. You could catch that error and change strategies to a
copy/delete sequence. That would be messier, but...
cheers,
Mark