# Pastebin Mus9JqBn use std::fs; use std::io::{BufReader, Read}; use std::path::Path; const BUFFER_SIZE: usize = 1024; fn main() { let dir1 = Path::new("/path/to/dir1"); let dir2 = Path::new("/path/to/dir2"); compare_directories(dir1, dir2); } fn compare_directories(dir1: &Path, dir2: &Path) { for entry in fs::read_dir(dir1).unwrap() { let entry = entry.unwrap(); let path1 = entry.path(); if entry.file_type().unwrap().is_dir() { let path2 = dir2.join(entry.file_name()); if !fs::metadata(&path2).is_ok() { println!("Directory not found: {}", path2.display()); continue; } compare_directories(&path1, &path2); } else { let path2 = dir2.join(entry.file_name()); if !fs::metadata(&path2).is_ok() { println!("File not found: {}", path2.display()); continue; } let mut buffer1 = Vec::new(); let mut buffer2 = Vec::new(); let mut file1 = BufReader::new(fs::File::open(&path1).unwrap()); let mut file2 = BufReader::new(fs::File::open(&path2).unwrap()); loop { let bytes_read1 = file1.read(&mut buffer1[..BUFFER_SIZE]).unwrap(); let bytes_read2 = file2.read(&mut buffer2[..BUFFER_SIZE]).unwrap(); if bytes_read1 != bytes_read2 || buffer1 != buffer2 { println!("Files differ: {} and {}", path1.display(), path2.display()); break; } if bytes_read1 == 0 || bytes_read2 == 0 { break; } } } } }