Ignores hidden files

This commit is contained in:
Dandaedre 2025-12-08 00:50:43 +01:00
parent d141f4e0c2
commit c10f2b9559
1 changed files with 11 additions and 1 deletions

View File

@ -3,7 +3,7 @@ use clap::Parser;
use regex::Regex;
use serde::Deserialize;
use std::{fs, path::PathBuf};
use walkdir::WalkDir;
use walkdir::{DirEntry, WalkDir};
use rayon::prelude::*; // brings `par_iter()` into scope
@ -82,6 +82,7 @@ fn main() -> Result<()> {
// ---------------------------------------------------------
let files: Vec<PathBuf> = WalkDir::new(&target_dir)
.into_iter()
.filter_entry(is_not_hidden)
.filter_map(|e| e.ok()) // skip errors
.filter(|e| e.file_type().is_file())
.map(|e| e.path().to_path_buf())
@ -114,3 +115,12 @@ fn process_file(path: &PathBuf, patterns: &[(Regex, String)]) -> Result<()> {
Ok(())
}
/// Return `true` if the path is *not* hidden.
fn is_not_hidden(entry: &DirEntry) -> bool {
// Skip anything that starts with a dot.
!entry
.file_name()
.to_str()
.is_some_and(|s| s.starts_with('.'))
}