find_matching_files¶
Provides utilities for finding files in a directory hierarchy using glob patterns. This module offers functions to efficiently filter files by include/exclude patterns, similar to .gitignore functionality. It supports recursive directory traversal, pattern matching, and duplicate handling, making it ideal for selectively processing files in complex directory structures while maintaining a clean filtering approach.
- docpack.find_matching_files.remove_dupes(lst: list) list[source]¶
Remove duplicates from a list while preserving order.
This function returns a new list containing unique elements from the input list, maintaining their original order. The input list remains unchanged, and the returned list has a different identity (i.e., a new object in memory).
- docpack.find_matching_files.process_include_exclude(include: list[str], exclude: list[str]) tuple[list[str], list[str]][source]¶
Process include and exclude glob patterns to prepare them for file filtering operations.
This function normalizes the include and exclude pattern lists by:
Setting a default include pattern of [”**/.”] if none provided
Removing duplicate patterns from both lists while preserving order
- docpack.find_matching_files.find_matching_files(dir_root: Path, include: list[str], exclude: list[str]) Iterable[Path][source]¶
Find files in a directory that match include patterns but not exclude patterns.
This function recursively searches through the directory tree starting from dir_root, filtering files using two sets of glob patterns:
First, files are included if they match any pattern in the include list (or all files if include list is empty)
Then, matching files are excluded if they match any pattern in the exclude list
Note
We use pathpick library under the hood.
- Parameters:
dir_root – The root directory to start the search from
include – List of glob patterns to match files for inclusion If empty, defaults to [”**/.”] (all files)
exclude – List of glob patterns to exclude files from the results If empty, no files are excluded