-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5ee29f5
commit ae905c6
Showing
1 changed file
with
36 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
extern crate jwalk; | ||
|
||
use jwalk::{DirEntry, Error, WalkDirGeneric}; | ||
use std::env; | ||
use std::fs::Metadata; | ||
|
||
fn main() { | ||
let path = env::args().skip(1).next().unwrap_or("./".to_owned()); | ||
let mut total: u64 = 0; | ||
|
||
for dir_entry_result in WalkDirGeneric::<((), Option<u64>)>::new(&path).process_read_dir( | ||
|_, _, _, dir_entry_results| { | ||
dir_entry_results.iter_mut().for_each(|dir_entry_result| { | ||
if let Ok(dir_entry) = dir_entry_result { | ||
if !dir_entry.file_type.is_dir() { | ||
dir_entry.client_state = | ||
Some(dir_entry.metadata().map(|m| m.len()).unwrap_or_default()); | ||
} | ||
} | ||
}) | ||
}, | ||
) { | ||
match dir_entry_result { | ||
Ok(dir_entry) => { | ||
if let Some(len) = &dir_entry.client_state { | ||
total += len; | ||
} | ||
} | ||
Err(error) => { | ||
println!("Read dir_entry error: {}", error); | ||
} | ||
} | ||
} | ||
|
||
println!("path: {} total bytes: {}", path, total); | ||
} |