...and deleting directories?

K

Kurt Euler

All-

Again related to the question I just posed: Is there a way to delete a directory structure on an NT machine from within Ruby code? I should think some syntax that includes rmdir would apply.

Thanks again!

-Kurt Euler
 
N

nobu.nokada

Hi,

At Wed, 8 Oct 2003 15:15:29 +0900,
Kurt said:
Again related to the question I just posed: Is there a way to
delete a directory structure on an NT machine from within
Ruby code? I should think some syntax that includes rmdir
would apply.

From [ruby-talk:83752]:

At Wed, 8 Oct 2003 15:42:04 +0900,
Gavin said:
require 'fileutils'

FileUtils.rm_rf(directory) # trash a directory tree
^^^^^^^^^^^^^^^^
 
C

Christoph

nobu.nokada wrote: wrote
....
^^^^^^^^^^^^^^^^

This doesn't work if the directory "directory" itself isn't readable.

Here is an example I created with cygwin (if cygwin isn't handy use
the explorer permission window or Microsoft's own xcaclcs tool).

$mkdir directory; chmod -w directory

E:\Ruby\Scripts>ruby -r fileutils -e "FileUtils.rm_rf('directory')"
E:/Ruby/lib/ruby/1.8/fileutils.rb:583:in `rmdir': Permission denied -
directory (Errno::EACCES)
from E:/Ruby/lib/ruby/1.8/fileutils.rb:583:in `remove_dir'
from E:/Ruby/lib/ruby/1.8/fileutils.rb:534:in `rm_r'
from E:/Ruby/lib/ruby/1.8/fileutils.rb:526:in `each'
from E:/Ruby/lib/ruby/1.8/fileutils.rb:526:in `rm_r'
from E:/Ruby/lib/ruby/1.8/fileutils.rb:550:in `rm_rf'
from -e:1


/Christoph
 
C

Christoph

Christoph wrote:

....
E:\Ruby\Scripts>ruby -r fileutils -e "FileUtils.rm_rf('directory')"
E:/Ruby/lib/ruby/1.8/fileutils.rb:583:in `rmdir': Permission denied -
directory (Errno::EACCES)
from E:/Ruby/lib/ruby/1.8/fileutils.rb:583:in `remove_dir'
from E:/Ruby/lib/ruby/1.8/fileutils.rb:534:in `rm_r'
from E:/Ruby/lib/ruby/1.8/fileutils.rb:526:in `each'
from E:/Ruby/lib/ruby/1.8/fileutils.rb:526:in `rm_r'
from E:/Ruby/lib/ruby/1.8/fileutils.rb:550:in `rm_rf'
from -e:1

It looks like that a recursive version of Chris Morris's
``File.chmod(0644, file)'' hint should do the trick - i.e.

ruby -r fileutils -e "File.chmod(0644,
'directory');FileUtils.rmdir('directory')"

works fine.


/Christoph
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,137
Messages
2,570,795
Members
47,342
Latest member
eixataze

Latest Threads

Top