fn collect_entries(path: &PathBuf, file_regex: Option<Regex>) -> io::Result<Vec<FileEntry>> {
        let mut entries: Vec<FileEntry> = vec![];
        if path.is_dir() {
            for entry in fs::read_dir(path)? {
                let entry = entry?;
                let epath = entry.path();
                if epath.is_dir() {
                    entries.push(FileEntry {
                        name: entry
                            .file_name()
                            .into_string()
                            .unwrap_or_else(|_| "".to_string()),
                        path: epath,
                        dir: true,
                    });
                } else if epath.is_file() {
                    let mut show = true;
                    if let Some(ref reg) = file_regex {
                        let filename = epath
                            .file_name()
                            .expect("Expect filename")
                            .to_str()
                            .expect("Easy conversion");
                        show = reg.is_match(filename);
                    }
                    if show {
                        entries.push(FileEntry {
                            name: entry
                                .file_name()
                                .into_string()
                                .unwrap_or_else(|_| "".to_string()),
                            path: epath,
                            dir: false,
                        });
                    }
                }
            }
        } else {
            entries.push(FileEntry {
                name: path
                    .file_name()
                    .expect("Files have names")
                    .to_str()
                    .unwrap_or("")
                    .to_string(),
                path: path.into(),
                dir: true,
            });
        }
        Ok(entries)
    }
/// Find the files below a directory
Find the files below a directory
Find the files below a directory
fn collect_entries(path: &PathBuf, file_regex: Option<Regex>) -> io::Result<Vec<FileEntry>> {
        let mut entries: Vec<FileEntry> = vec![];
        if path.is_dir() {
            for entry in fs::read_dir(path)? {
                let entry = entry?;
                let epath = entry.path();
                if epath.is_dir() {
                    entries.push(FileEntry {
                        name: entry
                            .file_name()
                            .into_string()
                            .unwrap_or_else(|_| "".to_string()),
                        path: epath,
                        dir: true,
                    });
                } else if epath.is_file() {
                    let mut show = true;
                    if let Some(ref reg) = file_regex {
                        let filename = epath
                            .file_name()
                            .expect("Expect filename")
                            .to_str()
                            .expect("Easy conversion");
                        show = reg.is_match(filename);
                    }
                    if show {
                        entries.push(FileEntry {
                            name: entry
                                .file_name()
                                .into_string()
                                .unwrap_or_else(|_| "".to_string()),
                            path: epath,
                            dir: false,
                        });
                    }
                }
            }
        } else {
            entries.push(FileEntry {
                name: path
                    .file_name()
                    .expect("Files have names")
                    .to_str()
                    .unwrap_or("")
                    .to_string(),
                path: path.into(),
                dir: true,
            });
        }
        Ok(entries)
    }
fn collect_entries ( path : & PathBuf , file_regex : Option < Regex > ) -> io :: Result < Vec < FileEntry > > { let mut entries : Vec < FileEntry > = vec ! [ ] ; if path . is_dir ( ) { for entry in fs :: read_dir ( path ) ? { let entry = entry ? ; let epath = entry . path ( ) ; if epath . is_dir ( ) { entries . push ( FileEntry { name : entry . file_name ( ) . into_string ( ) . unwrap_or_else ( | _ | " " . to_string ( ) ) , path : epath , dir : true , } ) ; } else if epath . is_file ( ) { let mut show = true ; if let Some ( ref reg ) = file_regex { let filename = epath . file_name ( ) . expect ( " " ) . to_str ( ) . expect ( " " ) ; show = reg . is_match ( filename ) ; } if show { entries . push ( FileEntry { name : entry . file_name ( ) . into_string ( ) . unwrap_or_else ( | _ | " " . to_string ( ) ) , path : epath , dir : false , } ) ; } } } } else { entries . push ( FileEntry { name : path . file_name ( ) . expect ( " " ) . to_str ( ) . unwrap_or ( " " ) . to_string ( ) , path : path . into ( ) , dir : true , } ) ; } Ok ( entries ) }
Find the files below a directory
Find the files below a directory
path
&PathBuf
file_regex
Option<Regex>
path
&PathBuf
file_regex
Option<Regex>