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.
pip install -r requirements.txtOr, as an installable package with a delete-my-files command:
pip install -e .
delete-my-files --folder ./Downloads --extension .tmpInteractive mode, same as the original:
python DeleteMyFiles.pyNon-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--extensionaccepts a comma-separated list, for example.tmp,.log,.bak.--recursivealso searches subfolders.--excludeskips a filename or path segment, matched as a glob pattern, for example.gitor*.bak. It can be passed more than once.--min-age-daysonly deletes files last modified at least this many days ago.--follow-symlinksincludes symlinks. They are skipped by default.--permanentdeletes files for real, bypassing the trash.--forceallows a run against a folder the script flags as a system or home directory.--dry-runlists the files that would be deleted, without deleting them. Use this first if you are unsure.--yesskips the confirmation prompt, for scripted use.--watch SECONDSrepeats the run on an interval untilCtrl+C. It requires--yesor--dry-run, since a prompt cannot be answered unattended.--verboseshows debug-level detail, including files skipped by--exclude,--min-age-days, or symlink filtering.--log-file PATHalso writes a timestamped record of the run to a file, independent of--verbose.
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.
pip install -e ".[dev]"
pytestTests 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.