Q:

Ruby program to delete an empty directory using Dir::unlink(), Dir::delete() methods

belongs to collection: Ruby Directories Programs

0

In this program, we will remove the empty directories using Dir::unlink()Dir::delete() methods. Then we will check given directories are removed or not using Dir::exists() method.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Program/Source Code:

The source code to delete an empty directory using Dir::unlink()Dir::delete() methods is given below. The given program is compiled and executed on Windows 10 Operating System successfully.

# Ruby program to delete an empty directory 
# using Dir::unlink(), Dir::delete() 
# methods

puts Dir::exists?("MyDir1");
puts Dir::exists?("MyDir2");

Dir::unlink("MyDir1");
Dir::delete("MyDir2");

puts Dir::exists?("MyDir1");
puts Dir::exists?("MyDir2");

Output:

true
true
false
false

Explanation:

In the above program, we removed the MyDir1MyDir2 directories using Dir::unlink()Dir::delete() methods. Then we checked given directories have been deleted or not using the Dir::exists() method. If directories have been deleted successfully then it will print "true" otherwise it will print "false".

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Ruby program to get the list of filenames matching... >>
<< Ruby program to get the current working directory ...