#content #contents-of-directory #deleting #empty-directory

empty_inside_dir

Empty the contents of a directory without deleting itself

2 stable releases

Uses new Rust 2024

1.1.0 Oct 12, 2025
1.0.0 Oct 12, 2025

#1154 in Filesystem

Download history 319/week @ 2025-10-08 36/week @ 2025-10-15 4/week @ 2025-10-22

359 downloads per month

Apache-2.0

9KB
103 lines

Empty Inside Directory

en(English) | zh(中文)

Empty the contents of a directory without deleting the directory itself. This is a simple and lightweight library with minimal functions.

Usage

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(())
}

Features

  • 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.

Open Source License

This crate is released under the Apache 2.0 License.

No runtime deps