Skip to main content

A utility for copying files based on pattern matching

Project description

Filesmith

PyPI version Python versions License

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

  1. Copy all .txt files from source to dest:

    filesmith /path/to/source /path/to/dest ".*\.txt$"
    
  2. Perform a dry run to see which .jpg files would be copied:

    filesmith /path/to/source /path/to/dest ".*\.jpg$" --dry-run
    
  3. Copy .log files newer than a specific date:

    filesmith /path/to/logs /path/to/backup ".*\.log$" --newermt 2023-10-27T10:00:00
    
  4. 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 ValueError if:
    • 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_file utility.
  • Improved copy_files:
    • Switched from print to structured logging.
    • More robust handling of ISO datetime / file-based --newermt filtering.
  • 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

filesmith-0.2.0.tar.gz (6.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

filesmith-0.2.0-py3-none-any.whl (5.8 kB view details)

Uploaded Python 3

File details

Details for the file filesmith-0.2.0.tar.gz.

File metadata

  • Download URL: filesmith-0.2.0.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

Hashes for filesmith-0.2.0.tar.gz
Algorithm Hash digest
SHA256 87d8314d599fab5eedb5ae01125862ee683f4dc61cd1567b78851fa5caa1daea
MD5 96edc6077dea1b7706a04d345a818009
BLAKE2b-256 5dfcef8c8f2ba96236d5b5a509ddd76bd61bb77dc07b5ba04183cd26ae624f01

See more details on using hashes here.

File details

Details for the file filesmith-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: filesmith-0.2.0-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

Hashes for filesmith-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 cd25183e3d519770396f487aee55955f00298a6068be2747cea2481c9b3fffb3
MD5 0f32abc442a60c04fb3c771e11ada82b
BLAKE2b-256 886dfdc5ae8aea08710cc098d458a337bd75d48fe0d1a0211ac7fa6d858e0e7b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page