Skip to main content

A collection of file manipulation and inspection utilities, including pattern-based file operations.

Project description

Filesmith

PyPI version Python versions License

A collection of file manipulation and inspection utilities, including pattern-based file operations and knapsack-based file selection.

Installation

You can install filesmith using pip:

pip install filesmith

Usage (CLI)

Filesmith provides a unified CLI with subcommands.

filesmith <command> [arguments] [options]

1. find-move

Find files and copy/move them.

filesmith find-move <src> <dst> [-p PATTERN] [-m {copy,move}] [-n] [-R]
  • src: Source directory.
  • dst: Destination directory.
  • -p, --pattern: Glob pattern (default: *).
  • -m, --mode: copy or move (default: copy).
  • -n, --dry-run: Show what would be done.
  • -R, --no-recursive: Do NOT search recursively.

Example:

filesmith find-move ./src ./backup -p "*.py"

2. knapsack

Knapsack-related operations.

copy

Copy a subset of files to a destination without exceeding a total size capacity.

filesmith knapsack copy <src_dir> <dest_dir> <capacity> [-p PATTERN] [-n] [-R]

Example:

# Copy up to 100MB of images
filesmith knapsack copy ./photos ./usb-drive 104857600 -p "*.jpg"

solve

Solve a general knapsack/subset-sum problem for integer items.

filesmith knapsack solve <capacity> <items...>

3. Legacy CLI

The original regex-based copy tool is available via:

filesmith-legacy copy <origin> <destination> <pattern> [--newermt REF] [-n] [-q]

Python API

Filesmith can also be used as a Python library.

from pathlib import Path
from filesmith import get_target_file, copy_files, find_files, FindMoveJob

# Locate a unique file
path = get_target_file("./data", "report", ".xlsx")

# Use the new job engine
job = FindMoveJob(src_root=Path("./src"), dest_root=Path("./dst"), pattern="*.txt")
job.run()

Key Functions

  • get_target_file(dir, key, ext): Finds exactly one matching file.
  • find_files(root, pattern, recursive, predicate): Advanced file finding.
  • copy_files(origin, destination, pattern, ...): Regex-based copy (legacy).
  • run_knapsack(items, capacity): Solves the subset-sum problem.
  • copy_files_by_capacity(src, dest, capacity, ...): Size-constrained copying.

Changelog

0.4.0

  • Added unified filesmith command with subcommands: find-move, knapsack.
  • Added filesmith-legacy for the previous regex-based CLI.
  • Expanded Python API in filesmith package.
  • Improved internal structure (finder, transfer, engine).

0.2.0

  • Added get_target_file utility.
  • Improved copy_files with structured logging and --newermt filtering.

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.4.0.tar.gz (16.7 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.4.0-py3-none-any.whl (13.3 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for filesmith-0.4.0.tar.gz
Algorithm Hash digest
SHA256 ddfa992ddf32b07279b70dc38357ceb8a0720ca6c257ec7eca7e79e033e07a00
MD5 e0f0a1cff2c860859068535c896e1fbe
BLAKE2b-256 e4c3b037b866105af6e8180ea75d2264d02321e697f4f3e7a9a8052f02260255

See more details on using hashes here.

File details

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

File metadata

  • Download URL: filesmith-0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 13.3 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.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 30f82647d0ea89307353208670a10dbff6fbe2bcfeae22a5e07aa9efee9bd3aa
MD5 27db5f6ab299edb9be0a4a2373a2d3d7
BLAKE2b-256 a0437adb93815813deeb4248294bb6aa8339f5a3ea078f3ec66171f3438d6332

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