[−][src]Function walkr::find
pub fn find(
dir: &Path,
search_str: &String,
cb: &dyn Fn(&DirEntry)
) -> Result<()>
Recursively search a directory for a files matching a regex and execute a closure on that regex.
Arguments
dir
- &Path of the directory to begin searching insearch_str
- &String containing the regex to match files oncb
-&Fn(&DirEntry)
to be called for each file match
Example
match walkr::find(Path::new("./"), &"\\.rs".to_owned(), &|d| { println!("File: {:?} matched!", d.file_name().into_string().unwrap()); // open the file and print the contents to stdout let mut f = File::open(d.path()).unwrap(); let mut s = String::new(); match f.read_to_string(&mut s) { Ok(_) => { println!("{:?}", s); }, Err(e) => panic!(e) } }) { Ok(_) => println!("done"), Err(e) => panic!(e) }