This Python module provides a FileMover
class designed to organize files by moving them into categorized sub-directories within a specified main output folder. It simplifies the process of sorting files based on their processing outcome (e.g., Successful
, Skipped
, Errors
), making it an essential utility for batch processing workflows.
FileMover
ClassThe module is centered around the FileMover
class, which handles all file organization and movement logic.
The primary role of the FileMover
is to take a source file and move it to a specific sub-folder within a pre-defined base output directory. This is particularly useful for scripts that process many files and need to sort them based on the result of the operation.
To use the FileMover
, you first need to create an instance of it.
from pathlib import Path
from file_operations import FileMover
# Initialize the mover with a path to your desired main output folder.
# This folder will be created automatically if it doesn't exist.
output_manager = FileMover(Path("C:/path/to/main_output"))
__init__(self, base_output_dir)
base_output_dir
(Path): The root folder where all categorized sub-folders will be created.move_file()
This is the main method for moving a file into a categorized sub-directory.
move_file(self, source_path, destination_folder_name: str)
source_path
(Path): The full path of the file you want to move.destination_folder_name
(str): The name of the sub-folder you want to move the file into (e.g., 'Skipped_NoOCRequired'
, 'Errors_Or_Empty'
).The logic of the FileMover
is straightforward and robust:
FileMover
is created with a path to a base output directory (e.g., ./output
). The script ensures this base directory exists.