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.
Kostas Z. (Guest)
on 2007-06-18 21: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
Kaldrenon (Guest)
on 2007-06-18 22:30
(Received via mailing list)
On Jun 18, 1:32 pm, Kostas Z. <removed_email_address@domain.invalid>
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.
(Guest)
on 2007-06-18 22:41
(Received via mailing list)
On Jun 18, 8:28 am, Kaldrenon <removed_email_address@domain.invalid> 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
Kostas Z. (Guest)
on 2007-06-19 00:47
removed_email_address@domain.invalid wrote:
> On Jun 18, 8:28 am, Kaldrenon <removed_email_address@domain.invalid> 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.