Reference¶
dsg_lib.common_functions.file_mover
¶
Module: file_mover Detailed file processing flow that continuously monitors and processes files from a source directory, optionally compresses them, and then moves them to a final destination. Ensures no files are lost during transfer.
Functions:
Name | Description |
---|---|
) -> None |
Continuously monitors the source directory for files matching the given pattern, moves them to a temporary directory, optionally compresses them, and then transfers them to the final directory. |
_process_file |
Path, temp_path: Path, final_path: Path, compress: bool) -> None: Handles the internal logic of moving and optionally compressing a single file. |
Usage Example:
from dsg_lib.common_functions.file_mover import process_files_flow
process_files_flow(
source_dir="/some/source",
temp_dir="/some/temp",
final_dir="/some/final",
file_pattern="*.txt",
compress=True
)
process_files_flow(source_dir, temp_dir, final_dir, file_pattern, compress=False, max_iterations=None)
¶
Continuously monitors a source directory for files. Moves files matching file_pattern to a temporary directory, optionally compresses them, then moves them to a final destination directory.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
source_dir
|
str
|
Path to the source directory to watch. |
required |
temp_dir
|
str
|
Path to the temporary directory for processing. |
required |
final_dir
|
str
|
Path to the final destination directory. |
required |
file_pattern
|
str
|
Glob pattern for matching files (e.g. "*.txt"). |
required |
compress
|
bool
|
If True, compress files before moving. Defaults to False. |
False
|
max_iterations
|
Optional[int]
|
Limit iterations in watch loop. Defaults to None. |
None
|
Returns:
Type | Description |
---|---|
None
|
None |
Raises:
Type | Description |
---|---|
Exception
|
Propagated if file operations fail. |
Example
process_files_flow("/source", "/temp", "/final", "*.pdf", compress=True)
Source code in dsg_lib/common_functions/file_mover.py
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
|