I am newbie on rust and trying an example to read dir on Win10 from:
https://rust-lang-nursery.github.io/rust-cookbook/file/dir.html
However the code cannot compile due to return result is expecting 2 type arguments:
std::io::Error
std::time::SystemTimeError
use std::fs;
fn main() -> Result<()> {
let current_dir = "C:/temp/";
println!(
"Entries modified in the last 24 hours in {:?}:",
current_dir
);
for entry in fs::read_dir(current_dir)? {
let entry = entry?;
let path = entry.path();
let metadata = fs::metadata(&path)?;
let last_modified = metadata.modified()?.elapsed()?.as_secs();
if last_modified < 24 * 3600 && metadata.is_file() {
println!(
"Last modified: {:?} seconds, is read only: {:?}, size: {:?} bytes, filename: {:?}",
last_modified,
metadata.permissions().readonly(),
metadata.len(),
path.file_name().ok_or("No filename")?
);
}
}
Ok(())
}
Here is the playground link: