0
use std::env;
use std::fs;
use std::path::PathBuf;
use std::path::Path;

fn find_file(start_dir: PathBuf, file: String) {
    
    let paths = fs::read_dir(start_dir).unwrap();

    for path in paths {
        let full_path = path.as_ref().unwrap().path();
        let is_directory = Path::new(&full_path).is_dir();


        if is_directory {
            println!("Name: {}{:?}", &full_path.display(), &is_directory);
            find_file(full_path.clone(), file.clone());
        } else {
            println!("Name: {}{:?}", &full_path.display(), &is_directory);
        }
    }
}

I am trying to make a function that iterates through a file tree from a given start point, and it works, however, it always gives an "os code 5 error"(access denied error) when going through certain folders(ones that require admin perms to open), so I'm wondering if there is a way to ignore that error and keep going with the program

William
  • 13
  • 3
  • Essentially, you need to actually handle the errors returned by `fs::read_dir` among others - this means removing the `unwrap`s and replacing them with `Result` handling. – PitaJ Oct 18 '22 at 21:22
  • @justinas thanks! This should help – William Oct 18 '22 at 21:31

0 Answers0