Empty the contents of a directory without deleting the directory itself. This is a simple and lightweight library with minimal functions.
The parameter's signature is impl AsRef<Path>,
which means it can accept any type that implements AsRef<Path>,
such as &Path, PathBuf, String, &str, etc.
use empty_inside_dir::empty_dir;
use std::path::Path;
fn main() -> Result<(), std::io::Error> {
...
empty_dir("xxx")?;
Ok(())
}- Safe: Only operates on directories, returns error for files.
- Idempotent: Returns
Ok(())for non-existent paths. - Recursive: Removes all contents including subdirectories.
- Preserves Directory: The directory itself remains intact.
This crate is released under the Apache 2.0 License.