ADVERTISEMENT
ADVERTISEMENT

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

Ruby Example: Write a program to delete an empty directory using Dir::unlink(), Dir::delete() methods.
Submitted by Nidhi, on February 21, 2022

Problem Solution:

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.

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 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".

Ruby Directories Programs »


ADVERTISEMENT
ADVERTISEMENT


Comments and Discussions!



ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.