Skip to content

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 FileValidationMixin

Mixin providing file validation utilities.

Provides methods for validating file extensions, paths, and retrieving files by extension.

Source

get_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

NameTypeDefaultDescription
directorystrDirectory to scan.
extensionsList[str]Extensions to search for.
recursiveboolTrueEnable recursive search.

Returns

  • List[str]List of found file paths.
Source

is_valid_extensionstaticmethod

def is_valid_extension(filename: str, extensions: List[str]) -> bool:

Check if a file has a valid extension.

Parameters

NameTypeDescription
filenamestrFile name.
extensionsList[str]List of allowed extensions (with the dot).

Returns

  • boolTrue if the extension is valid.
Source

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

NameTypeDefaultDescription
pathstrPath to validate.
must_be_fileboolFalseMust be a file.
must_be_dirboolFalseMust be a directory.

Returns

  • boolTrue if the path is valid.
Source
Built with Kiln