std-function

fs::remove_file: remove one file entry

Remove a file name, not necessarily the underlying bytes immediately; open handles and other links may retain access. Use a fresh disposable working directory exclusively controlled by this program. Expected stdout (not executed): false Common mistake: Treating removal as secure erasure.

Formal Syntax & Structure

rust syntaxrust
fs::remove_file(path) -> io::Result<()>

Working Example

Example Snippetrust
fn main() {    use std::fs::{self, File};    use std::io::{Read, Write};    fs::create_dir("bm-fixture").expect("fresh working directory required");    let p = std::path::Path::new("bm-fixture").join("note.txt");    File::create_new(&p).unwrap();    fs::remove_file(&p).unwrap();    println!("{}", p.try_exists().unwrap());}
Rust Reference