forked from Cutieguwu/raven
22 lines
522 B
Rust
22 lines
522 B
Rust
use std::path::{Path, PathBuf};
|
|
|
|
pub fn expand_files<P: AsRef<Path>>(path: P) -> anyhow::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())
|
|
}
|