Q:

Rust program to remove an existing file

belongs to collection: Rust File I/O Programs

0

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

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 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.

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

total answers (1)

Rust program to check a specified file exists or n... >>
<< Rust program to append data into an existing file...