Rust program to create a directory

Rust | File I/O Example: Write a program to create a directory.
Submitted by Nidhi, on November 01, 2021

Problem Solution:

In this program, we will create a specified directory in the current directory using the create_dir() function.

Program/Source Code:

The source code to create a directory is given below. The given program is compiled and executed on UBUNTU 18.04 successfully.

// Rust program to create a directory

use std::fs;

fn main() -> std::io::Result<()> {
    println!("MyDir directory created successfully\n");


$ rustc

$ ./main
MyDir directory created successfully


Here, we created an empty directory MyDir using the create_dir() function and print the appropriate message on the console screen.

Rust File I/O Programs »

Comments and Discussions!

Load comments ↻

Copyright © 2024 All rights reserved.