Forum: Ruby Deleting a non empty directory

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Fe8d0cff4475071aa3d9154d8f2c8eca?d=identicon&s=25 Kostas Zoumbatianos (kostas)
on 2007-06-18 19:31
Hi, I am getting an exception when I use Dir.delete on a non empty
directory.
What should I do to remove a non empty directory?

Thanks,
Kostas
5dbb7a37b65f9e4ed415a97ab39300e5?d=identicon&s=25 Kaldrenon (Guest)
on 2007-06-18 20:30
(Received via mailing list)
On Jun 18, 1:32 pm, Kostas Zoumbatianos <zoumbatia...@gmail.com>
wrote:
> Hi, I am getting an exception when I use Dir.delete on a non empty
> directory.
> What should I do to remove a non empty directory?
>
> Thanks,
> Kostas
>
> --
> Posted viahttp://www.ruby-forum.com/.

Use Dir.each to iterate over the items in the dir, and call
File.delete on them. Then call Dir.delete.
8310c5a7c769345114597bcdef111488?d=identicon&s=25 bmunat@gmail.com (Guest)
on 2007-06-18 20:41
(Received via mailing list)
On Jun 18, 8:28 am, Kaldrenon <kaldre...@gmail.com> wrote:
> > --
> > Posted viahttp://www.ruby-forum.com/.
>
> Use Dir.each to iterate over the items in the dir, and call
> File.delete on them. Then call Dir.delete.

Or use FileUtils::rm_rf:

http://www.ruby-doc.org/core/classes/FileUtils.html#M004368

Be careful though. ;-)

b
Fe8d0cff4475071aa3d9154d8f2c8eca?d=identicon&s=25 Kostas Zoumbatianos (kostas)
on 2007-06-18 22:47
bmunat@gmail.com wrote:
> On Jun 18, 8:28 am, Kaldrenon <kaldre...@gmail.com> wrote:
>> > --
>> > Posted viahttp://www.ruby-forum.com/.
>>
>> Use Dir.each to iterate over the items in the dir, and call
>> File.delete on them. Then call Dir.delete.
>
> Or use FileUtils::rm_rf:
>
> http://www.ruby-doc.org/core/classes/FileUtils.html#M004368
>
> Be careful though. ;-)
>
> b

Thanks a lot!
This topic is locked and can not be replied to.