ADVERTISEMENT
ADVERTISEMENT

Rust program to create a directory using create_dir_all() function

Rust | File I/O Example: Write a program to create a directory using create_dir_all() function.
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_all() function.

Note: The create_dir_all() function is used to create a directory if it does not exist.

Program/Source Code:

The source code to create a directory using the create_dir_all() function is given below. The given program is compiled and executed on UBUNTU 18.04 successfully.

// Rust program to create a directory 
// using create_dir_all() function

use std::fs;

fn main() -> std::io::Result<()> {
    fs::create_dir_all("NewDir")?;
    println!("NewDir directory created successfully\n");
    Ok(())
}

Output:

$ rustc main.rs

$ ./main
NewDir directory created successfully

Explanation:

Here, we created a directory MyDir using the create_dir_all() function and print the appropriate message.

Rust File I/O Programs »



ADVERTISEMENT
ADVERTISEMENT


Comments and Discussions!



ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.