File Utils¶
List files in a directory with specified extensions or all files if no extensions are provided.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
directory |
Union[str, Path]
|
The directory path as a string or Path object. |
required |
extensions |
Optional[List[str]]
|
A list of file extensions to filter. Default is None, which lists all files. |
None
|
Returns:
Type | Description |
---|---|
List[Path]
|
A list of Path objects for the matching files. |
Examples:
import supervision as sv
# List all files in the directory
files = sv.list_files_with_extensions(directory='my_directory')
# List only files with '.txt' and '.md' extensions
files = sv.list_files_with_extensions(
directory='my_directory', extensions=['txt', 'md'])