added utils module
This commit is contained in:
31
src/utils.rs
Normal file
31
src/utils.rs
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
use std::{
|
||||||
|
fs::{self, DirEntry},
|
||||||
|
path::{Path, PathBuf},
|
||||||
|
};
|
||||||
|
|
||||||
|
pub fn walk_files_recursive(
|
||||||
|
root: impl AsRef<Path>,
|
||||||
|
) -> std::io::Result<impl Iterator<Item = DirEntry>> {
|
||||||
|
fn visit(dir: &Path, out: &mut Vec<DirEntry>) -> std::io::Result<()> {
|
||||||
|
for entry in fs::read_dir(dir)? {
|
||||||
|
let entry = entry?;
|
||||||
|
let path = entry.path();
|
||||||
|
let file_type = entry.file_type()?;
|
||||||
|
|
||||||
|
if file_type.is_dir() {
|
||||||
|
visit(&path, out)?;
|
||||||
|
} else if file_type.is_file() {
|
||||||
|
out.push(entry);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut files = Vec::new();
|
||||||
|
visit(root.as_ref(), &mut files)?;
|
||||||
|
Ok(files.into_iter())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn path_to_lowercase(path: impl AsRef<Path>) -> PathBuf {
|
||||||
|
PathBuf::from(path.as_ref().to_string_lossy().to_lowercase())
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user