Skip to main content

Library to delete files with rules

Project description

file_delete_manager

Library to manage and delete files according to configurable rules.

This package provides a small CLI and a programmatic API to:

  • delete files older than a given age
  • keep only the most recent N files in a directory
  • ensure total directory size stays below a cap by deleting files
  • move selected files to a trash directory

Requires Python 3.8+

Installation

pip install file-delete-manager

CLI Usage

An entry point file_delete_manager is provided. Run file_delete_manager --help for top-level options.

Main subcommands:

  • delete-by-age (alias: age)
    • Delete files older than a specified age. Use --older-than with units, e.g. 7d, 30m, 3600s.
  • delete-by-count (alias: count)
    • Keep only the most recent N files. Use --keep-last to set how many to keep.
  • delete-by-size (alias: sizecap)
    • Delete files until the total size stays under --max-total-bytes.
  • move-to-trash (alias: trash)
    • Move files to a specified --trash-dir instead of deleting.

Common options available to each subcommand:

  • --recursive / --no-recursive — descend into subdirectories (default: recursive)
  • --follow-symlinks — follow symbolic links when walking directories
  • --dry-run — simulate actions without changing files
  • --delete-empty-dirs — remove directories that become empty after deletions
  • --include-pattern / --exclude-pattern — glob patterns to include/exclude files
  • --min-size / --max-size — size filters in bytes
  • --log-level — set logging level (DEBUG, INFO, WARNING, ERROR)

Example (dry-run deleting files older than 30 days):

file_delete_manager delete-by-age C:\path\to\dir --older-than 30d --dry-run

Example (keep only last 5 files):

file_delete_manager delete-by-count C:\path\to\dir --keep-last 5 --dry-run

Programmatic API

Import the package and call the helpers directly from Python:

from file_delete_manager.core import DeleteOptions, delete_by_age, delete_by_count
from file_delete_manager.rules import delete_if_over_size, move_to_trash

opts = DeleteOptions(dry_run=True, recursive=True)
# delete files older than 7 days (dry-run)
deleted = delete_by_age("/tmp/mydir", "7d", opts)

# keep only the last 10 files (real run)
opts.dry_run = False
deleted = delete_by_count("/tmp/mydir", 10, opts)

# enforce total size cap
deleted = delete_if_over_size("/tmp/mydir", max_total_bytes=10_000_000, options=opts)

# move to trash
moved = move_to_trash("/tmp/myfile.txt", "/tmp/trash", options=opts)

API summary:

  • DeleteOptions — dataclass with flags for dry_run, recursive, include/exclude patterns, size filters, follow_symlinks, delete_empty_dirs, and sort_key.
  • delete_by_age(directory, older_than, options) — deletes files older than the specified age.
  • delete_by_count(directory, keep_last, options, sort_key='mtime') — removes files to keep only the last N.
  • delete_if_over_size(directory, max_total_bytes, options, sort_key=None) — trims files until total size <= max_total_bytes.
  • move_to_trash(path, trash_dir, options) — moves files into a trash directory instead of deleting.

Contributing

Contributions are welcome. Please open issues or pull requests. Follow the project's coding style and include tests for behavior changes.

License

This project is licensed under the MIT License. See LICENSE for details.

Notes

  • The package metadata (pyproject.toml) should expose the CLI entry point file_delete_manager which maps to file_delete_manager.cli:main.
  • Ensure pyproject.toml and package metadata are updated to reflect the new project name (for example, change the name field and any script entry points). If pyproject.toml still lists libtpz you may want to update it to file_delete_manager.

For more detailed usage and examples, see manual.md in the repository.

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

file_delete_manager-0.1.2.tar.gz (10.8 kB view details)

Uploaded Source

Built Distribution

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

file_delete_manager-0.1.2-py3-none-any.whl (10.5 kB view details)

Uploaded Python 3

File details

Details for the file file_delete_manager-0.1.2.tar.gz.

File metadata

  • Download URL: file_delete_manager-0.1.2.tar.gz
  • Upload date:
  • Size: 10.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.9

File hashes

Hashes for file_delete_manager-0.1.2.tar.gz
Algorithm Hash digest
SHA256 916ff927621391731dd2a9ebcfd8261339d0cd1f4a07302afc0fb9677d7d32f3
MD5 8998f3e2b4b97f8a61798563174a4d6b
BLAKE2b-256 6dcde2d23dfc42c8b38b7431253c8e317cb54f3a786c35fb5000e26c6c412033

See more details on using hashes here.

File details

Details for the file file_delete_manager-0.1.2-py3-none-any.whl.

File metadata

File hashes

Hashes for file_delete_manager-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 b79d3bdc3dfe4fbd4a1895aaf2d61628eaeeeee4f3524dddce573c321929f312
MD5 9ae235d9df842ba779f3a62860a3382e
BLAKE2b-256 6af527784741da3c82c1c5270f86edab75ac9e4c78c560d2f2d085c89683aeac

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