Home »
Rust »
Rust Programs
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<()> {
fs::create_dir("MyDir")?;
println!("MyDir directory created successfully\n");
Ok(())
}
Output:
$ rustc main.rs
$ ./main
MyDir directory created successfully
Explanation:
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 »