hfutils.utils.walk
This module provides utilities for file handling, specifically for walking through directories and retrieving file paths. It includes a function to recursively search for files in a specified directory based on a given pattern.
The primary function is walk_files, which allows users to easily obtain relative paths of all files within a directory structure, making it useful for file management tasks, data processing, and more.
walk_files
- hfutils.utils.walk.walk_files(directory: str, pattern: str | None = None) Iterator[str] [source]
Recursively walk through a directory and yield relative paths of all files.
This function takes a directory path and a pattern to search for files. It uses the glob module to find all files that match the specified pattern within the directory and its subdirectories. The yielded paths are relative to the specified directory.
- Parameters:
directory (str) – The root directory to start walking.
pattern (str) – The pattern to match files against, defaults to
**/*
which matches all files.
- Returns:
An iterator that yields relative paths of all files in the directory.
- Return type:
Iterator[str]
- Example:
>>> for file in walk_files('/path/to/directory'): ... print(file)