I can't get FileUtils to delete a directory

T

Tara Keane

Hi there,
I created a test folder with two sub-folders inside and now I want to
delete the main folder.
In irb I typed:
require 'fileutils'
FileUtils.rm_f("test")

I'm running the command from C: and the folder is directly off C:
I assumed it should just delete but nothing's happening...
I know Dir.delete won't delete a folder if there is something in it. I
want to figure out how to delete the folder in one command rather than
having to go through it deleting all the sub folders one by one. I'm
sure there's a way to do this?
 
A

Ammar Ali

Hi there,
I created a test folder with two sub-folders inside and now I want to
delete the main folder.
In irb I typed:
require 'fileutils'
FileUtils.rm_f("test")

This is similar to the command line version on unix systems, where
removing a directory recursively require the -r option. The same
applies here. Use rm_rf instead of rm_f.

FileUtils.rm_rf('test')

Regards,
Ammar
 
T

Tara Keane

I don't get it...

(newbie - sorry)
But I do know one

A SQL query walks up to a table in a bar and says 'mind if I join you?'
 
J

Jeremy Bopp

I don't get it...

(newbie - sorry)

rm -rf has a history of being accidentally used to clobber very
important data from a Unix system. If you're running as the root user
on Unix, you have the ability to wipe out the entire filesystem,
including the operating system's files, rather than just your personal
home directory and any other limited directories to which you have write
access. Under older systems, you needed to have the password for the
root user in order to operate in its name. Thus, to really f**k things
up, you need root's password. :)

The moral of the story is to use rm -rf and any similar facility such as
FileUtils.rm_rf with extreme caution.

-Jeremy
 

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

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top