1use std::{
12 fs,
13 path::{Path, PathBuf},
14};
15#[derive(Debug, Clone)]
16pub struct FileInfo {
17 pub name: String,
18 pub path: PathBuf,
19 pub extension: Option<String>,
20}
21
22impl FileInfo {
23 pub fn new(name: String, path: &Path) -> Self {
24 Self {
25 name,
26 path: path.to_path_buf(),
27 extension: path.extension().map(|e| e.to_string_lossy().into_owned()),
28 }
29 }
30}
31
32pub fn find_files_recurse(path: &PathBuf, filter: &str, ignore_list: &[String]) -> std::io::Result<Vec<FileInfo>> {
33 let mut libs: Vec<_> = vec![];
34 for entry in fs::read_dir(path)? {
35 let entry = entry?;
36 let path = entry.path().clone();
37 let name = entry.file_name().to_string_lossy().into_owned();
38
39 if path.is_dir() && !ignore_list.contains(&name) {
40 let sub_libs = find_files_recurse(&path, filter, ignore_list)?;
41 for lib in sub_libs {
42 libs.push(lib);
43 }
44 } else if path.is_file() && name.contains(filter) && !ignore_list.contains(&name) {
45 libs.push(FileInfo::new(name, path.as_path()));
46 }
47 }
48
49 Ok(libs)
50}