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