pub fn dir_walk<'a>(
dir_path: &'a str
) -> impl Iterator<Item = SysResult<String>> + 'a
Available on crate feature
kernel
only.Expand description
Returns an interator over the files within a directory, and all its subdirectories, recursively.
This is a high-level abstraction over HFINDFILE
iteration functions.
§Examples
use winsafe::{self as w, prelude::*};
// Ordinary for loop
for file_path in w::path::dir_walk("C:\\Temp") {
let file_path = file_path?;
println!("{}", file_path);
}
// Closure with try_for_each
w::path::dir_walk("C:\\Temp")
.try_for_each(|file_path| {
let file_path = file_path?;
println!("{}", file_path);
Ok(())
})?;
// Collecting into a Vec
let all = w::path::dir_walk("C:\\Temp")
.collect::<w::SysResult<Vec<_>>>()?;
// Transforming and collecting into a Vec
let all = w::path::dir_walk("C:\\Temp")
.map(|file_path| {
let file_path = file_path?;
Ok(format!("PATH: {}", file_path))
})
.collect::<w::SysResult<Vec<_>>>()?;