-
-
Save letheed/3203dea78b6a6c031177d323e06d33b3 to your computer and use it in GitHub Desktop.
r/rust/comments/98japr/
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
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