Skip to content

Instantly share code, notes, and snippets.

@BurntSushi
Created August 19, 2018 13:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BurntSushi/37cf13595516acda9bd45e5003be4ea9 to your computer and use it in GitHub Desktop.
Save BurntSushi/37cf13595516acda9bd45e5003be4ea9 to your computer and use it in GitHub Desktop.
extern crate walkdir;
use walkdir::WalkDir;
use std::fs::File;
use std::io::Read;
fn main() {
let nul = 0;
let mut bytes_count: i32;
for entry in WalkDir::new("./").into_iter().filter_map(|e| e.ok()) {
if entry.file_type().is_file() {
let mut file = File::open(entry.path()).unwrap();
bytes_count = 0;
let mut s: Vec<u8> = Vec::with_capacity(file.metadata().unwrap().len() as usize);
file.read_to_end(&mut s).unwrap();
for b in s.into_iter() {
if b == nul {
println!("{} bytes={} binary file", entry.path().display(), bytes_count);
break
}
bytes_count += 1;
}
println!("{} bytes={}", entry.path().display(), bytes_count)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment