letpaths=fs::read_dir(basedir).expect("could not read directory");
letpaths={
matchfs::read_dir(basedir){
Ok(p)=>p,
Err(e)=>{
matche.kind(){
std::io::ErrorKind::NotFound=>{// attempt to create the missing directory
matchstd::fs::create_dir(basedir){
Ok(_)=>fs::read_dir(basedir).expect("could not read newly created directory"),// created patch directory successfully. return it to paths
Err(ee)=>panic!("Failed to create directory \"{}\".\n{:?}",basedir,ee),// we already know the path doesnt exist so no need to check for AlreadyExists error. panic
}
},
_=>panic!("Unable to read directory \"{}\".\n{:?}",basedir,e),