// recursively find file with given keyword
recursively find file with given keyword
recursively find file with given keyword
fn findfile(target: &path::PathBuf, keyword: &str) {
    // get list of files in target directory
    let files = target
        .read_dir()
        .expect(&format!("{} is not a directory", target.display()));
    for dir_entry in files {
        // get PathBuf
        let path = dir_entry.unwrap().path();
        // recusive if path
        if path.is_dir() {
            findfile(&path, keyword);
        }
        // to string
        let fname = path.file_name().unwrap().to_string_lossy();
        // check if file name contains keyword
        if None == fname.find(keyword) {
            continue;
        }
        // display path and file name
        println!("{}", path.to_string_lossy());
    }
}
fn findfile ( target : & path :: PathBuf , keyword : & str ) { // get list of files in target directory let files = target . read_dir ( ) . expect ( & format ! ( " " target display ( ) ) ) ; for dir_entry in files { // get PathBuf let path = dir_entry . unwrap ( ) . path ( ) ; // recusive if path if path . is_dir ( ) { findfile ( & path , keyword ) ; } // to string let fname = path . file_name ( ) . unwrap ( ) . to_string_lossy ( ) ; // check if file name contains keyword if None == fname . find ( keyword ) { continue ; } // display path and file name println ! ( " " path to_string_lossy ( ) ) ; } }
recursively find file with given keyword
recursively find file with given keyword
target
&path::PathBuf
keyword
&str