From 7d1cdcbdb188a6172f835c4960163af1052eaf2a Mon Sep 17 00:00:00 2001 From: Del Date: Mon, 2 Aug 2021 15:52:56 +0000 Subject: [PATCH] Add basic directory listing & config reading --- src/main.rs | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/src/main.rs b/src/main.rs index ab81fd3..d658bd2 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,4 +1,5 @@ use serde::{Deserialize, Serialize}; +use std::error::Error; use std::{env, fs}; #[derive(Debug, Serialize, Deserialize)] @@ -20,10 +21,19 @@ fn main() { let conf : Config = serde_yaml::from_str(&conf_str) .expect("invalid config format"); - - let input_paths = fs::read_dir(conf.input_path).unwrap(); - - for path in input_paths { - println!("{}", path.unwrap().path().display()) - } + load_paths(&conf.input_path).unwrap(); +} + +fn load_paths(root_dir : &str) -> Result<(), Box> { + let entries = fs::read_dir(root_dir)?; + + for entry in entries { + let entry = entry?; + let meta = entry.metadata()?; + if meta.is_file() { + println!("{}", entry.path().display()); + } + } + + Ok(()) }