]> git.r.bdr.sh - rbdr/page/blame - src/file_finder.rs
Handle layout error better
[rbdr/page] / src / file_finder.rs
CommitLineData
1e2d00b6
RBR
1use crate::file_handler::{File, FileHandler};
2use std::fs::read_dir;
3use std::path::PathBuf;
4
4fd89b80
RBR
5pub fn find_files(directory_path: &PathBuf) -> Vec<File> {
6 return find_files_recursively(directory_path, directory_path);
5643a041
RBR
7}
8
9fn find_files_recursively(root_path: &PathBuf, directory_path: &PathBuf) -> Vec<File> {
1e2d00b6
RBR
10 let mut result: Vec<File> = vec![];
11 let file_handler = FileHandler::default();
5643a041 12 let entries = read_dir(&directory_path).unwrap();
1e2d00b6
RBR
13 for entry in entries {
14 let path = entry.unwrap().path();
5643a041 15 let relative_path = path.strip_prefix(&root_path).unwrap();
ea529736 16 if relative_path.starts_with(".git") || relative_path.starts_with(".gitignore") {
1e2d00b6
RBR
17 continue;
18 }
19 if path.is_dir() {
5643a041 20 result.append(&mut find_files_recursively(&root_path, &path))
1e2d00b6
RBR
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}