Skip to content

Instantly share code, notes, and snippets.

@kirugan
Created October 11, 2025 22:24
Show Gist options
  • Save kirugan/fc3c539f56376d33f1816d85372f4172 to your computer and use it in GitHub Desktop.
Save kirugan/fc3c539f56376d33f1816d85372f4172 to your computer and use it in GitHub Desktop.
Script that cleans up png files (screenshots) that are located alongside it
#!/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