Q:

Rust program to create a directory

0

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

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

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.

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now