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
Install locally from the project root:
pip install .
Or, if published to PyPI in the future:
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-thanwith units, e.g.7d,30m,3600s.
- Delete files older than a specified age. Use
- delete-by-count (alias: count)
- Keep only the most recent N files. Use
--keep-lastto set how many to keep.
- Keep only the most recent N files. Use
- delete-by-size (alias: sizecap)
- Delete files until the total size stays under
--max-total-bytes.
- Delete files until the total size stays under
- move-to-trash (alias: trash)
- Move files to a specified
--trash-dirinstead of deleting.
- Move files to a specified
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_managerwhich maps tofile_delete_manager.cli:main. - Ensure
pyproject.tomland package metadata are updated to reflect the new project name (for example, change thenamefield and any script entry points). Ifpyproject.tomlstill listslibtpzyou may want to update it tofile_delete_manager.
For more detailed usage and examples, see manual.md in the repository.
Project details
Release history Release notifications | RSS feed
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 file_delete_manager-0.1.1.tar.gz.
File metadata
- Download URL: file_delete_manager-0.1.1.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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cefbad41e288225833c043dd12f0105188001c1cd3920e45bda5dd23840e4ef0
|
|
| MD5 |
247f1722d1f44ce55c059f75b21d29b3
|
|
| BLAKE2b-256 |
e9b72c1794f59b0ce41951e1cdeccc3c0d3fd5398a6acdb16b6770a931b65288
|
File details
Details for the file file_delete_manager-0.1.1-py3-none-any.whl.
File metadata
- Download URL: file_delete_manager-0.1.1-py3-none-any.whl
- Upload date:
- Size: 10.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
182b870ceff6d62b942332daae1e0fcb3d6194f1ba865e2754ad2bdc8e36b4f4
|
|
| MD5 |
8793e19065ab12cacf2763f669f70896
|
|
| BLAKE2b-256 |
1d25a8dc66b8aecea16f1d55c6ff8e119765b866fd86e34a2b0195ac09bb67a2
|