Skip to content

Repository files navigation

DeleteMyFilesPy

This script bulk-deletes files of a given extension from a folder. It runs on any operating system. Deleted files go to the system trash by default, so a mistake is recoverable.

Setup

pip install -r requirements.txt

Or, as an installable package with a delete-my-files command:

pip install -e .
delete-my-files --folder ./Downloads --extension .tmp

Usage

Interactive mode, same as the original:

python DeleteMyFiles.py

Non-interactive mode:

python DeleteMyFiles.py --folder ./Downloads --extension .tmp
python DeleteMyFiles.py --folder ./Downloads --extension .tmp,.log --recursive --dry-run
python DeleteMyFiles.py --folder ./Downloads --extension .tmp --min-age-days 7
python DeleteMyFiles.py --folder ./Downloads --extension .tmp --exclude ".git" --exclude "*.bak"
python DeleteMyFiles.py --folder ./Downloads --extension .tmp --watch 3600 --yes
  1. --extension accepts a comma-separated list, for example .tmp,.log,.bak.
  2. --recursive also searches subfolders.
  3. --exclude skips a filename or path segment, matched as a glob pattern, for example .git or *.bak. It can be passed more than once.
  4. --min-age-days only deletes files last modified at least this many days ago.
  5. --follow-symlinks includes symlinks. They are skipped by default.
  6. --permanent deletes files for real, bypassing the trash.
  7. --force allows a run against a folder the script flags as a system or home directory.
  8. --dry-run lists the files that would be deleted, without deleting them. Use this first if you are unsure.
  9. --yes skips the confirmation prompt, for scripted use.
  10. --watch SECONDS repeats the run on an interval until Ctrl+C. It requires --yes or --dry-run, since a prompt cannot be answered unattended.
  11. --verbose shows debug-level detail, including files skipped by --exclude, --min-age-days, or symlink filtering.
  12. --log-file PATH also writes a timestamped record of the run to a file, independent of --verbose.

Safety

The script refuses to run against a folder it resolves to a filesystem root, your home directory, or a known system directory name, unless --force is passed. Deletions go to the trash unless --permanent is set. Symlinks are skipped unless --follow-symlinks is set, so a recursive run cannot delete outside the target folder through a link.

Development

pip install -e ".[dev]"
pytest

Tests live in tests/ and cover file matching, the age/exclude/symlink filters, the dangerous-path guard, and both delete modes. send2trash calls are mocked in tests, since CI runners don't reliably provide a system trash. A GitHub Actions workflow (.github/workflows/tests.yml) runs the suite on Ubuntu, Windows, and macOS, on every push and pull request.

About

Cross-platform CLI to bulk-delete files by extension, with trash-based safety, age/exclude filters, and dry-run.

Topics

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages