feat(dirlist): Add listing of directory

This commit is contained in:
Andreas Mieke 2023-11-02 19:25:54 +01:00
parent d09c1d60f9
commit 2b47cf5321
4 changed files with 56 additions and 1 deletions

21
src/directory.rs Normal file
View 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
}

View file

@ -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());
}
}