-
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.
add new 'count' example to count as fast as possible
- Loading branch information
Showing
2 changed files
with
43 additions
and
6 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,35 @@ | ||
//! Collect the amount of directories and files as fast as possible. | ||
mod shared; | ||
|
||
use clap::Parser; | ||
use jwalk::WalkDirGeneric; | ||
|
||
fn main() { | ||
let args = shared::Args::parse(); | ||
|
||
let parallelism = args.parallelism(); | ||
let threads = args.threads(); | ||
let path = args.root.unwrap_or_else(|| ".".into()); | ||
let (mut dirs, mut files, mut symlinks) = (0, 0, 0); | ||
for dir_entry_result in WalkDirGeneric::<((), Option<u64>)>::new(&path) | ||
.skip_hidden(false) | ||
.parallelism(parallelism) | ||
{ | ||
match dir_entry_result { | ||
Ok(dir_entry) => { | ||
if dir_entry.file_type.is_dir() { | ||
dirs += 1; | ||
} else if dir_entry.file_type.is_file() { | ||
files += 1; | ||
} else if dir_entry.file_type.is_symlink() { | ||
symlinks += 1 | ||
} | ||
} | ||
Err(error) => { | ||
println!("Read dir_entry error: {}", error); | ||
} | ||
} | ||
} | ||
|
||
println!("dirs: {dirs}, files: {files}, symlinks: {symlinks} (threads: {threads})"); | ||
} |
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