diff --git a/Cargo.lock b/Cargo.lock index 6ad2050..aa348d1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -372,6 +372,7 @@ dependencies = [ "serde", "serde_json", "stderrlog", + "walkdir", ] [[package]] @@ -407,6 +408,15 @@ version = "1.0.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1ad4cc8da4ef723ed60bced201181d83791ad433213d8c24efffda1eec85d741" +[[package]] +name = "same-file" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502" +dependencies = [ + "winapi-util", +] + [[package]] name = "scopeguard" version = "1.2.0" @@ -573,6 +583,16 @@ version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a" +[[package]] +name = "walkdir" +version = "2.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d71d857dc86794ca4c280d616f7da00d2dbfd8cd788846559a6813e6aa4b54ee" +dependencies = [ + "same-file", + "winapi-util", +] + [[package]] name = "wasi" version = "0.11.0+wasi-snapshot-preview1" diff --git a/Cargo.toml b/Cargo.toml index a373a12..1490eab 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,3 +12,4 @@ log = "0.4.20" serde = { version = "1.0.190", features = ["derive"] } serde_json = "1.0.108" stderrlog = "0.5.4" +walkdir = "2.4.0" diff --git a/src/directory.rs b/src/directory.rs new file mode 100644 index 0000000..795fb88 --- /dev/null +++ b/src/directory.rs @@ -0,0 +1,21 @@ +use std::path::PathBuf; + +use walkdir::{DirEntry, WalkDir}; + +fn is_not_hidden(entry: &DirEntry) -> bool { + entry + .file_name() + .to_str() + .map(|s| entry.depth() == 0 || !s.starts_with(".")) + .unwrap_or(false) +} + +pub fn list_files(path: PathBuf) -> Vec{ + let mut entries: Vec = vec![]; + WalkDir::new(path) + .into_iter() + .filter_entry(|e| is_not_hidden(e)) + .filter_map(|v| v.ok()) + .for_each(|x| entries.push(x.into_path())); + entries +} \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index 4e6b3d6..b7a8c42 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,8 +1,9 @@ mod config; +mod directory; use log::*; use clap::Parser; -use std::path::PathBuf; +use std::{path::PathBuf, env}; #[derive(Parser, Debug)] #[command(author, version, about, long_about = None)] @@ -55,4 +56,16 @@ fn main() { info!("Found config: {:#?}", cfg); + let search_path = if args.path.is_none() { + env::current_dir().unwrap() + } else { + args.path.unwrap() + }; + + let files = directory::list_files(search_path); + + for file in files { + info!("Found: {}", file.to_str().unwrap()); + } + } \ No newline at end of file