mirror of
https://github.com/zyllian/zyllian.github.io.git
synced 2025-05-09 18:16:43 -07:00
18 lines
425 B
Rust
18 lines
425 B
Rust
//! Module containing various utilities.
|
|
|
|
use std::path::Path;
|
|
|
|
/// Simple helper to remove the contents of a directory without removing the directory itself.
|
|
pub fn remove_dir_contents(path: &Path) -> anyhow::Result<()> {
|
|
for entry in path.read_dir()? {
|
|
let entry = entry?;
|
|
let path = entry.path();
|
|
if path.is_file() {
|
|
std::fs::remove_file(&path)?;
|
|
} else {
|
|
std::fs::remove_dir_all(&path)?;
|
|
}
|
|
}
|
|
|
|
Ok(())
|
|
}
|