Delete a directory with all sub-directories an files

Hi.

I would like to delete a directory. In this directory are other
directories an files. So I have to delete this subdirectories an files
at first. Now I search a good solution to solve this problem. My first
idea was to look in the given directory and if there are subdirectories
to look in this directories… Is this the right way? Is there a ready
function for this little problem? Or has anybody written a function for it?

greetings
Dirk Einecke

require ‘fileutils’
FileUtils.rm_rf(“somerandomdir”)

#untested

···

On Sat, 17 Apr 2004 21:53:48 +0200, Dirk Einecke wrote:

I would like to delete a directory. In this directory are other
directories an files. So I have to delete this subdirectories an files
at first. Now I search a good solution to solve this problem. My first
idea was to look in the given directory and if there are subdirectories
to look in this directories… Is this the right way? Is there a ready
function for this little problem? Or has anybody written a function for it?

rm -rf directory
:slight_smile:

···

On Sat, 17 Apr 2004 20:53:48 +0200, Dirk Einecke wrote:

Hi.

I would like to delete a directory. In this directory are other
directories an files. So I have to delete this subdirectories an files
at first. Now I search a good solution to solve this problem. My first
idea was to look in the given directory and if there are subdirectories
to look in this directories… Is this the right way? Is there a ready
function for this little problem? Or has anybody written a function for
it?

greetings
Dirk Einecke

Hi Simon.

Simon Strandgaard wrote:

I would like to delete a directory. In this directory are other
directories an files. So I have to delete this subdirectories an files
at first. Now I search a good solution to solve this problem. My first
idea was to look in the given directory and if there are subdirectories
to look in this directories… Is this the right way? Is there a ready
function for this little problem? Or has anybody written a function for it?

require ‘fileutils’
FileUtils.rm_rf(“somerandomdir”)

Sorry - I have not this library (and it is not possible to install this
library). But I’ve ftools. Can me help this library?

greetings
Dirk Einecke

“Kristof Bastiaensen” kristof@vleeuwen.org schrieb im Newsbeitrag
news:4082752a$0$973$a0ced6e1@news.skynet.be…

Hi.

I would like to delete a directory. In this directory are other
directories an files. So I have to delete this subdirectories an files
at first. Now I search a good solution to solve this problem. My first
idea was to look in the given directory and if there are
subdirectories
to look in this directories… Is this the right way? Is there a ready
function for this little problem? Or has anybody written a function
for
it?

greetings
Dirk Einecke

rm -rf directory
:slight_smile:

Another one liner would be:

Dir[File.join(dir, ‘**’, ‘*’)].reverse.each {|f| (File.directory? ? Dir :
File).delete f}
:slight_smile:

Note: this one is portable also.

robert
···

On Sat, 17 Apr 2004 20:53:48 +0200, Dirk Einecke wrote:

You could update to Ruby 1.8+ where fileutils.rb is a standard module.
If that doesn’t work you can simply put a copy of fileutils.rb from a
recent distribution into your working script directory and include it
from there. No need to “install” it.

And if for some reason that isn’t possible, then you can always just
copy the code straight from the module into your script. In this case it
looks like you’d need to copy in less than 25 lines of code for the
rm_rf command and the rm_r command. The only time I wouldn’t do this is
if there were license concerns. In any case, the fileutils.rb module has
a great example of how to do this. :slight_smile:

-michael

···

On Sat, 2004-04-17 at 14:44, Dirk Einecke wrote:

require ‘fileutils’
FileUtils.rm_rf(“somerandomdir”)

Sorry - I have not this library (and it is not possible to install this
library). But I’ve ftools. Can me help this library?

Hi Michael.

Michael C. Libby wrote:

You could update to Ruby 1.8+ where fileutils.rb is a standard module.

That’s not possible to because Ruby is running on the server of my ISP.

If that doesn’t work you can simply put a copy of fileutils.rb from a
recent distribution into your working script directory and include it
from there. No need to “install” it.

Okay. I will try this. But where can I get the newest version? I found
this two pages:

http://www.loveruby.net/archive/

http://cvs.rose.radionet.fi/cgi-bin/viewcvs.cgi/roseroot/extras/ruby/lib/
(http://cvs.rose.radionet.fi/cgi-bin/viewcvs.cgi/*checkout*/roseroot/extras/ruby/lib/fileutils.rb?rev=1.1.1.1)

greetings
Dirk Einecke

Go to the official CVS repository to get the latest version.

http://www.ruby-lang.org/cgi-bin/cvsweb.cgi/ruby/lib/fileutils.rb

… and click download. Then just stick it in the same directory as the
other files, and viola! :slight_smile:

cheers,
–Mark

···

On Apr 17, 2004, at 1:54 PM, Dirk Einecke wrote:

If that doesn’t work you can simply put a copy of fileutils.rb from a
recent distribution into your working script directory and include it
from there. No need to “install” it.

Okay. I will try this. But where can I get the newest version?

Hi Mark.

Mark Hubbart wrote:

Go to the official CVS repository to get the latest version.

http://www.ruby-lang.org/cgi-bin/cvsweb.cgi/ruby/lib/fileutils.rb

… and click download. Then just stick it in the same directory as the
other files, and viola! :slight_smile:

Thanks.
But one thing is strange:

Working fine:
http://cvs.rose.radionet.fi/cgi-bin/viewcvs.cgi/*checkout*/roseroot/extras/ruby/lib/fileutils.rb?rev=1.1.1.1

Does not work:
http://www.ruby-lang.org/cgi-bin/cvsweb.cgi/~checkout~/ruby/lib/fileutils.rb?rev=1.41;content-type=text%2Fplain

Okay - well that’s one thing for the next day. Now I will go to sleep
(it’s 00:48am here in germany) :slight_smile:

greetings
Dirk Einecke