1use std::path::PathBuf;
2use std::error::Error;
3
4pub fn see_dir<'a>(dir: PathBuf, with_dirs: bool) -> Result<Vec<PathBuf>, &'a str> {
5 let mut list: Vec<PathBuf> = Vec::new();
6 for entry in match std::fs::read_dir(dir.clone()) {Ok(e) => e, Err(_s) => return Err("Could not read dir")} {
7 let entry = match entry {
8 Ok(e) => e,
9 Err(_e) => return Err("Could not convert to DirEntry"),
10 };
11 if entry.path().is_dir() {
12 if with_dirs {
13 list.push(entry.path().to_owned());
14 }
15 let mut sub: Vec<PathBuf> = Vec::new();
16 sub = see_dir(entry.path(), with_dirs)?;
17 list.extend(sub);
18 } else {
19 list.push(entry.path().to_owned());
20 }
21 }
22 Ok(list)
23}