Files
raven/crates/fs/src/lib.rs
2026-02-15 09:36:04 -05:00

25 lines
596 B
Rust

use std::path::{Path, PathBuf};
pub const EXT_TOML: &str = ".toml";
pub const EXT_LOCK: &str = ".lock";
pub fn expand_files<P: AsRef<Path>>(path: P) -> std::io::Result<Vec<PathBuf>> {
let path = path.as_ref();
if path.is_file() {
return Ok(vec![path.to_path_buf()]);
}
Ok(std::fs::read_dir(path)?
.filter_map(|entry| {
let path = entry.ok()?.path();
if path.is_dir() {
Some(expand_files(path).ok()?)
} else {
Some(vec![path])
}
})
.flatten()
.collect())
}