use cf::FileSystem; use std::env; fn main() { let dir_name = env::args().nth(1).unwrap(); let _size = FileSystem::dir_size(dir_name).unwrap() as f64; let units = "KB MB GB TB".split_whitespace().collect::>(); let ans = units.iter().fold((_size, "B"), |(n, w), u| { if n > 1024.0 { (n / 1024.0, u) } else { (n, w) } }); println!("{:.2} {}", ans.0, ans.1); }