Skip to content

Empty the contents of a directory without deleting the directory itself.

License

aprosail/empty_inside_dir

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.