×

Ruby Tutorial

Ruby Basics

Ruby Control Statements

Ruby Methods

Ruby Classes and Methods

Ruby Arrays

Ruby Sets

Ruby Strings

Ruby Classes & Objects

Ruby Hash

Ruby Tools

Ruby Functions

Ruby Built-in Functions

Misc.

Ruby Programs

Ruby program to remove a specified directory

Last Updated : December 15, 2025

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


Comments and Discussions!

Load comments ↻


Advertisement
Advertisement
Advertisement

Copyright © 2025 www.includehelp.com. All rights reserved.