]> git.r.bdr.sh - rbdr/page/blob - src/file_finder.rs
105a99928a0df5fd9b04921f275df189d22bc776
[rbdr/page] / src / file_finder.rs
1 use crate::file_handler::{File, FileHandler};
2 use std::fs::read_dir;
3 use std::path::PathBuf;
4
5 pub fn find_files(directory_path: &PathBuf) -> Vec<File> {
6 return find_files_recursively(directory_path, directory_path);
7 }
8
9 fn find_files_recursively(root_path: &PathBuf, directory_path: &PathBuf) -> Vec<File> {
10 let mut result: Vec<File> = vec![];
11 let file_handler = FileHandler::default();
12 let entries = read_dir(&directory_path).unwrap();
13 for entry in entries {
14 let path = entry.unwrap().path();
15 let relative_path = path.strip_prefix(&root_path).unwrap();
16 if relative_path.starts_with(".git") {
17 continue;
18 }
19 if path.is_dir() {
20 result.append(&mut find_files_recursively(&root_path, &path))
21 } else {
22 let file_type = file_handler.identify(&path);
23 result.push(File {
24 path: path,
25 file_type: file_type,
26 });
27 }
28 }
29 return result;
30 }