I'd like to delete a directory that may or may not contain files or other directories. Looking in the Ruby docs I found Dir.rmdir but it won't delete non-empty dir. Is there a convenience method that let's me do this? Or do I need to write a recursive method to examine everything below the directory?
+1
A:
On non-Windows systems, the following will work:
system("rm -rf #{dir}")
Denis Hennessy
2009-03-04 02:13:34
You forgot quotes; what if the path is /home/bob/Some Other Dir ?
Paul Betts
2009-03-04 02:15:25
A:
A pure Ruby way:
require 'fileutils'
FileUtils.rm_rf("/directory/to/go")
If you need thread safety: (warning, changes working directory)
FileUtils.rm_rf("directory/to/go", :secure=>true)
kraryal
2009-04-14 04:24:19