pub fn find_files(dir: &Path, pattern: &str) -> Result<Vec<PathBuf>>Expand description
Recursively finds files matching a pattern in a directory tree.
This function performs a recursive search through the directory tree, matching files whose names contain the specified pattern. The search is case-sensitive and uses simple string matching (not regex).
§Arguments
dir- The directory to search inpattern- The pattern to match in filenames (substring match)
§Returns
A vector of PathBufs for all matching files, or an error if the directory
cannot be read.
§Examples
use agpm_cli::utils::fs::find_files;
use std::path::Path;
// Find all Rust source files
let rust_files = find_files(Path::new("src"), ".rs")?;
// Find all markdown files
let md_files = find_files(Path::new("docs"), ".md")?;
// Find files with "test" in the name
let test_files = find_files(Path::new("."), "test")?;§Behavior
- Searches recursively through all subdirectories
- Only returns regular files (not directories or symlinks)
- Uses substring matching (case-sensitive)
- Returns empty vector if no matches found
- Continues searching even if some subdirectories are inaccessible
§Performance
For large directory trees or when searching for many different patterns,
consider using external tools like fd or implementing caching for repeated searches.