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.
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 MyDir1, MyDir2 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".
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.
Output:
Explanation:
In the above program, we removed the MyDir1, MyDir2 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