Created
October 11, 2025 22:24
-
-
Save kirugan/fc3c539f56376d33f1816d85372f4172 to your computer and use it in GitHub Desktop.
Script that cleans up png files (screenshots) that are located alongside it
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python3 | |
| import time | |
| from pathlib import Path | |
| # Number of days to keep screenshots | |
| DAYS_TO_KEEP = 30 | |
| # Get the script's directory | |
| script_dir = Path(__file__).parent | |
| # Calculate the cutoff time (30 days ago) | |
| cutoff_time = time.time() - (DAYS_TO_KEEP * 24 * 60 * 60) | |
| deleted_count = 0 | |
| # Iterate through all PNG files in the current directory | |
| for file_path in script_dir.glob('*.png'): | |
| # Delete if older than 30 days | |
| if file_path.stat().st_mtime < cutoff_time: | |
| file_path.unlink() | |
| deleted_count += 1 | |
| print(f"Deleted {deleted_count} PNG screenshots older than {DAYS_TO_KEEP} days") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment