sok.file_operations.mixins.validation
Validation mixin for file operations.
Provides utilities to validate files and paths:
- Extension validation
- Path existence checking
- File retrieval by extension
FileValidationMixin
class FileValidationMixinMixin providing file validation utilities.
Provides methods for validating file extensions, paths, and retrieving files by extension.
Sourceget_files_by_extensionstaticmethod
def get_files_by_extension( directory: str, extensions: List[str], recursive: bool = True,) -> List[str]:Retrieve all files in a directory with the given extensions.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
directory | str | Directory to scan. | |
extensions | List[str] | Extensions to search for. | |
recursive | bool | True | Enable recursive search. |
Returns
List[str]List of found file paths.
is_valid_extensionstaticmethod
def is_valid_extension(filename: str, extensions: List[str]) -> bool:Check if a file has a valid extension.
Parameters
| Name | Type | Description |
|---|---|---|
filename | str | File name. |
extensions | List[str] | List of allowed extensions (with the dot). |
Returns
boolTrue if the extension is valid.
validate_path_existsstaticmethod
def validate_path_exists( path: str, must_be_file: bool = False, must_be_dir: bool = False,) -> bool:Validate that a path exists and matches the expected type.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
path | str | Path to validate. | |
must_be_file | bool | False | Must be a file. |
must_be_dir | bool | False | Must be a directory. |
Returns
boolTrue if the path is valid.