feat(dirlist): Add listing of directory
This commit is contained in:
parent
d09c1d60f9
commit
2b47cf5321
20
Cargo.lock
generated
20
Cargo.lock
generated
|
@ -372,6 +372,7 @@ dependencies = [
|
||||||
"serde",
|
"serde",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
"stderrlog",
|
"stderrlog",
|
||||||
|
"walkdir",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
@ -407,6 +408,15 @@ version = "1.0.15"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "1ad4cc8da4ef723ed60bced201181d83791ad433213d8c24efffda1eec85d741"
|
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]]
|
[[package]]
|
||||||
name = "scopeguard"
|
name = "scopeguard"
|
||||||
version = "1.2.0"
|
version = "1.2.0"
|
||||||
|
@ -573,6 +583,16 @@ version = "0.2.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a"
|
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]]
|
[[package]]
|
||||||
name = "wasi"
|
name = "wasi"
|
||||||
version = "0.11.0+wasi-snapshot-preview1"
|
version = "0.11.0+wasi-snapshot-preview1"
|
||||||
|
|
|
@ -12,3 +12,4 @@ log = "0.4.20"
|
||||||
serde = { version = "1.0.190", features = ["derive"] }
|
serde = { version = "1.0.190", features = ["derive"] }
|
||||||
serde_json = "1.0.108"
|
serde_json = "1.0.108"
|
||||||
stderrlog = "0.5.4"
|
stderrlog = "0.5.4"
|
||||||
|
walkdir = "2.4.0"
|
||||||
|
|
21
src/directory.rs
Normal file
21
src/directory.rs
Normal file
|
@ -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<PathBuf>{
|
||||||
|
let mut entries: Vec<PathBuf> = 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
|
||||||
|
}
|
15
src/main.rs
15
src/main.rs
|
@ -1,8 +1,9 @@
|
||||||
mod config;
|
mod config;
|
||||||
|
mod directory;
|
||||||
|
|
||||||
use log::*;
|
use log::*;
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
use std::path::PathBuf;
|
use std::{path::PathBuf, env};
|
||||||
|
|
||||||
#[derive(Parser, Debug)]
|
#[derive(Parser, Debug)]
|
||||||
#[command(author, version, about, long_about = None)]
|
#[command(author, version, about, long_about = None)]
|
||||||
|
@ -55,4 +56,16 @@ fn main() {
|
||||||
|
|
||||||
info!("Found config: {:#?}", cfg);
|
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());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in a new issue