A utility for copying files based on pattern matching
Project description
Filesmith
A command-line utility for copying files based on pattern matching, with support for filtering by modification time, plus a helper function for selecting uniquely matched files.
Overview
Filesmith is a Python utility that helps you copy files from one directory to another based on regular expression patterns. It's particularly useful for selective file copying, backup operations, and automated file management tasks.
It also includes get_target_file, a reliable helper for retrieving a single uniquely identified file by substring and optional extension filter.
Installation
You can install filesmith using pip:
pip install filesmith
Usage (CLI)
filesmith <origin> <destination> <pattern> [options]
Arguments
origin: The source directory.destination: The destination directory.pattern: The regex pattern to match filenames against.
Options
--newermt <file_or_isodate>: Only copy files newer than a reference file's modification time or a given ISO date/datetime.-n,--dry-run: Show which files would be copied without actually copying them.-q,--quiet: Suppress output for successfully copied files.
Examples
-
Copy all .txt files from
sourcetodest:filesmith /path/to/source /path/to/dest ".*\.txt$"
-
Perform a dry run to see which .jpg files would be copied:
filesmith /path/to/source /path/to/dest ".*\.jpg$" --dry-run
-
Copy .log files newer than a specific date:
filesmith /path/to/logs /path/to/backup ".*\.log$" --newermt 2023-10-27T10:00:00
-
Copy .py files that are newer than
main.py:filesmith /path/to/src /path/to/old_src ".*\.py$" --newermt /path/to/src/main.py
Python Utility: get_target_file
Filesmith includes a small but powerful helper function to locate exactly one matching file in a directory.
Usage
from filesmith import get_target_file
file_path = get_target_file("/path/to/dir", "report", ".xlsx")
print(file_path)
Features
- Ensures exactly one match.
- Raises
ValueErrorif:- No files match.
- More than one file matches.
- Optional extension filtering:
get_target_file("data", "2024", ".csv")
This is ideal when processing pipelines rely on single expected inputs, such as weekly exports or naming‑convention‑based file detection.
Changelog
0.2.0
- Added
get_target_fileutility. - Improved
copy_files:- Switched from
printto structuredlogging. - More robust handling of ISO datetime / file-based
--newermtfiltering.
- Switched from
- Extended full test coverage (
pytest).
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file filesmith-0.2.1.tar.gz.
File metadata
- Download URL: filesmith-0.2.1.tar.gz
- Upload date:
- Size: 6.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a62b893c2ec7abc8947edf2e2637128068582acf7098d953b1c31ed4e359548b
|
|
| MD5 |
4ac5b38965e9ba9526903338166ff15f
|
|
| BLAKE2b-256 |
bed9be7be8c53fe6b12b464004762974bc3ecbe2612fd06b115a69e9e4072165
|
File details
Details for the file filesmith-0.2.1-py3-none-any.whl.
File metadata
- Download URL: filesmith-0.2.1-py3-none-any.whl
- Upload date:
- Size: 5.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2876c5d331603204b6a687167db804c0d39b3870044d69da2a26990f9cafe626
|
|
| MD5 |
d34b71207f7fee18fa097e0cdd65580e
|
|
| BLAKE2b-256 |
dbadff6dc1313749427b0f51229e0c1e92f767e7c0ce7b63e4d4ceeeb635b754
|