×

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 create a directory

Last Updated : December 15, 2025

Problem Solution

In this program, we will create a directory using Dir.mkdir() method and print the appropriate message.

Program/Source Code

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

# Ruby program to create a directory

if (Dir.mkdir("mydir") == 0)
	puts "Directory created successfully";
else
	puts "Directory creation failed";
end

Output

Directory created successfully

Explanation

In the above program, we created a directory mydir using Dir.mkdir() method. The Dir.mkdir() method returns 0 on successful creation of directory.

Ruby Directories Programs »


Advertisement
Advertisement


Comments and Discussions!

Load comments ↻


Advertisement
Advertisement
Advertisement

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