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).

0.3.0

  • Added new CLI: filesmith-find-move
  • Integrated core.copy_files with the new engine (finder / transfer / FindMoveJob)

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.3.0.tar.gz (12.0 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.3.0-py3-none-any.whl (9.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: filesmith-0.3.0.tar.gz
  • Upload date:
  • Size: 12.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.2

File hashes

Hashes for filesmith-0.3.0.tar.gz
Algorithm Hash digest
SHA256 04b81bc66fedbaa6e322c5fa0419d0523872650c110bbcd33125d227a080af1f
MD5 e68d60deed50453b2242b013792b8149
BLAKE2b-256 cc3c9b7e3fa58add7b17462c9f574364f0413ef7a127e01311aff07df4a9460a

See more details on using hashes here.

File details

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

File metadata

  • Download URL: filesmith-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 9.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.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4615bb11d8320e809f95c2f5f267c28c2bbf35a7679b4468b356f5c751d37824
MD5 7fd9a59d3c91aeb585d97c44184d0749
BLAKE2b-256 6400398e57e5a4fe71c3e02df0a72098b8b937ccddceb12b74cf2dfc044d04c3

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