Ruby - File Directory Deleting

Introduction

Deleting a directory is similar to deleting a file:

Dir.delete("testdir") 

Dir.unlink and Dir.rmdir perform exactly the same function.

You can use absolute pathnames.

If a directory isn't empty, you cannot delete it with a call to Dir.delete.

You need to iterate through each of the subdirectories and files and remove them.

Or you can use the rm_f method of the FileUtils library that comes with Ruby:

require 'fileutils' 
FileUtils.rm_f(directory_name) 

Related Topic