Rust program to remove an existing file

Rust | File I/O Example: Write a program to remove an existing file.
Submitted by Nidhi, on October 30, 2021

Problem Solution:

In this program, we will remove a specified file using the remove_file() function and print the appropriate message.

Program/Source Code:

The source code to remove an existing file is given below. The given program is compiled and executed on UBUNTU 18.04 successfully.

// Rust program to remove an existing file

use std::fs;

fn main() {
   fs::remove_file("sample.txt").expect("Unable to remove file");
   println!("File samplet.txt is removed successfully");
}

Output:

$ rustc main.rs

$ ./main
File samplet.txt is removed successfully

Explanation:

Here, we removed the specified file "sample.txt" and printed the appropriate message.

Rust File I/O Programs »



ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT


Top MCQs

Comments and Discussions!




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.