file_operation/delete/sync/fn.rs
1use std::{io::Error, path::Path};
2
3/// Deletes a file at the given path.
4///
5/// # Arguments
6///
7/// - `&str` - The file path to delete.
8///
9/// # Returns
10///
11/// - `Result<(), std::io::Error>` - Ok if the file was deleted successfully, Err with error details otherwise.
12pub fn delete_file(path: &str) -> Result<(), Error> {
13 std::fs::remove_file(path)
14}
15
16/// Deletes a directory and all its contents.
17///
18/// # Arguments
19///
20/// - `&str` - The directory path to delete.
21///
22/// # Returns
23///
24/// - `Result<(), std::io::Error>` - Ok if the directory was deleted successfully, Err with error details otherwise.
25pub fn delete_dir(path: &str) -> Result<(), Error> {
26 let dir_path: &Path = Path::new(path);
27 std::fs::remove_dir_all(dir_path)?;
28 Ok(())
29}