Skip to content

Instantly share code, notes, and snippets.

@letheed

letheed/main.rs Secret

Created August 19, 2018 14:07
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 letheed/3203dea78b6a6c031177d323e06d33b3 to your computer and use it in GitHub Desktop.
Save letheed/3203dea78b6a6c031177d323e06d33b3 to your computer and use it in GitHub Desktop.
r/rust/comments/98japr/
extern crate walkdir;
use std::fs::File;
use std::io::{self, Read};
use walkdir::WalkDir;
fn main() -> Result<(), io::Error> {
let mut buffer = Vec::new();
for entry in WalkDir::new("./").into_iter().filter_map(|e| e.ok()) {
if !entry.file_type().is_file() {
continue
}
let path = entry.path();
let mut file = File::open(path)?;
buffer.clear();
file.read_to_end(&mut buffer)?;
if let Some(idx) = buffer.iter().position(|&b| b == 0) {
println!("{} bytes={} binary file", path.display(), idx);
} else {
println!("{} bytes={}", path.display(), buffer.len());
}
}
Ok(())
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment