ff_util/lib.rs
1pub mod run {
2 use std::path::Path;
3
4 use colored::*;
5 pub fn run(dir: &Path, required_ext: &String) {
6 // We use the read_dir method to read the directory given by the user and it is stored in a
7 // variable for future use
8 let files = std::fs::read_dir(dir).unwrap();
9
10 // Now we loop over the files vector and checks if the file contains the extension or the
11 // filename provided by the user
12 for file in files {
13 if let Ok(f) = &file {
14 if let Some(f_as_str) = f.file_name().to_str() {
15 let file_ext: Vec<&str> = f_as_str.split(".").collect();
16 for ext in &file_ext {
17 if ext.contains(required_ext) {
18 for matched_file in &file {
19 if let Some(matched) = matched_file.file_name().to_str() {
20 println!("{}", matched.bold().yellow());
21 }
22 }
23 }
24 }
25 }
26 }
27 }
28 }
29}