Creating an automatic folder cleaner can be very useful for managing disk space and keeping your files organized. Below is a Python script that automatically cleans a specified folder by deleting files older than a certain number of days. This script can be run periodically (e.g., via a scheduled task or cron job).
Automatic Folder Cleaner in Python
How It Works:
-
The script checks all files in the given folder.
-
It deletes files last modified more than
days_olddays ago. -
It skips folders and only deletes files.
-
Prints progress and summary.
How to Use:
-
Change the value of
folder_to_cleanto the folder you want cleaned. -
Set
days_thresholdto the age in days after which files will be deleted. -
Run the script manually or set it up as a scheduled task (Windows Task Scheduler or Linux cron job).
If you want, I can help you create a version that moves files to the recycle bin instead of permanent deletion, or one that archives old files rather than deleting them. Just let me know!