Q:

Rust program to remove an existing file

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)

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now