pub fn delete_file<P: AsRef<Path>>(path: P)Expand description
Deletes a file at the specified path if it exists.
§Arguments
path- The path to the file to delete (can be a&str,String,Path, orstd::path::PathBuf).
§Panics
If some error is encountered while deleting the file at path.
§Examples
§Using a string literal
use file_io::{delete_file, save_string_to_file};
use std::path::Path;
// Create a file to delete later.
let path: &str = "file_to_delete_1.txt";
save_string_to_file("Hello, world!", path);
// Verify that the file exists.
assert!(Path::new(path).exists());
// Now delete the file.
delete_file(path);
// Verify that the file no longer exists.
assert!(!Path::new(path).exists());§Using a Path reference
use file_io::{delete_file, save_string_to_file};
use std::path::Path;
// Create a file to delete later.
let path: &Path = Path::new("file_to_delete_2.txt");
save_string_to_file("Hello, world!", path);
// Verify that the file exists.
assert!(path.exists());
// Now delete the file.
delete_file(path);
// Verify that the file no longer exists.
assert!(!path.exists());