use std::{fs,env,path}; use std::error::Error; use std::os::unix::fs::MetadataExt; fn main() -> Result<(), Box> { let args: Vec = env::args().collect(); let dir = match args.len() { 0 | 1 => path::Path::new("."), _other => path::Path::new(&args[2]), }; // header is basically a constant print!("\x01"); println!("{}\x1D", ["file_name", "size", "mtime"].join("\x1E")); println!("{}\x1D", ["string", "integer+bytes", "datetime"].join("\x1E")); print!("\x02"); for entry in fs::read_dir(dir)? { let entry = entry?; let metadata = entry.metadata()?; let filename: String = entry.file_name() .into_string() .or_else(|_| Err(format!("Invalid entry")))?; let mtime = chrono::DateTime::::from_utc( chrono::NaiveDateTime::from_timestamp(metadata.mtime(), 0), chrono::Utc); println!("{}\x1D", [ filename, metadata.size().to_string(), mtime.to_rfc3339_opts(chrono::SecondsFormat::AutoSi, true), ].join("\x1E")); } Ok(()) }