A few days ago I posted asking for ideas for 20 small automations to build.
I decided to start with something simple: sorting my screenshots.
It did not go simple at first.
I accidentally moved files into a folder that didn’t exist…
…which caused Linux to merge all my screenshots into one cursed mega‑image.
So that was fun.
Anyway, I rebuilt the script properly, made it cross‑platform, and now it safely sorts screenshots into year‑month folders.
Should I build more like this?
Final script:
from pathlib import Path
import datetime
import shutil
base = Path.home() / "Pictures" / "Screenshots"
base.mkdir(parents=True, exist_ok=True)
for f in base.rglob("*.png"):
file_month = datetime.datetime.fromtimestamp(f.stat().st_ctime).strftime("%Y-%m")
month_folder = base / file_month
month_folder.mkdir(exist_ok=True)
shutil.move(str(f), str(month_folder / f.name))