Ruby program to remove a specified directory

Ruby Example: Write a program to remove a specified directory.
Submitted by Nidhi, on February 20, 2022

Problem Solution:

In this program, we will remove a specified directory using Dir.rmdir() method.

Program/Source Code:

The source code to remove a specified directory is given below. The given program is compiled and executed on Windows 10 Operating System successfully.

# Ruby program to remove 
# a specified directory

puts Dir.exists?("mydir"); 

Dir.rmdir("mydir"); 

puts Dir.exists?("mydir");

Output:

true
false

Explanation:

In the above program, we used Dir.rmdir() method to remove the specified directory. Here we checked directory exists or not using Dir.exists?() method and print returned value.

Ruby Directories Programs »


ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT


Top MCQs

Comments and Discussions!




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.