in src/co_op_translator/utils/common/file_utils.py [0:0]
def filter_files(directory: str | Path, excluded_dirs) -> list:
"""
Filter and return only the files in the given directory, excluding specified directories.
Args:
directory (str | Path): The directory path to search for files.
excluded_dirs (set): A set of directory names to exclude from the search.
Returns:
list: A list of Path objects representing only the files (excluding specified directories).
"""
directory = Path(directory)
files = []
# Recursively traverse the directory
for path in directory.rglob("*"):
# Check if the path is a file and does not contain any excluded directories
if path.is_file() and not any(
excluded_dir in path.parts for excluded_dir in excluded_dirs
):
files.append(path)
return files