Skip to content

Instantly share code, notes, and snippets.

@JoeBlakeB
Created July 9, 2026 15:50
Show Gist options
  • Select an option

  • Save JoeBlakeB/3fd30a74cdd66070a3a144e0b46dcf89 to your computer and use it in GitHub Desktop.

Select an option

Save JoeBlakeB/3fd30a74cdd66070a3a144e0b46dcf89 to your computer and use it in GitHub Desktop.
A simple python script to move screenshots into a subfolder as I take screenshots so often that it gets really cluttered without subfolders, this puts them into a new subfolder each month.
#!/usr/bin/env python3
# A simple python script to move screenshots in the screenshots folder into subfolders based on their datetime.
# Usage:
# - Edit the SCREENSHOTS_DIR to be wherever your screenshots folder is
# - Schedule this script to run at a regular interval, for example on windows using Task Scheduler
# (ideally immediately after a login so that the root folder never updates while you're looking at it)
import datetime
import os
import re
import time
from pathlib import Path
SCREENSHOTS_DIR = r"C:\Users\Jo\Screenshots"
ARCHIVE_OLDNESS = 24 * 60 * 60
RENAME_REGEX = re.compile(r"Screenshot \([0-9]*\).png")
def logRun():
script_dir = os.path.dirname(os.path.abspath(__file__))
file_path = os.path.join(script_dir, "runs.txt")
with open(file_path, "a") as file:
file.write(f"{datetime.datetime.now()}\n")
def main():
for path in Path(SCREENSHOTS_DIR).iterdir():
if not os.path.isfile(path): continue
filetype = str(path).split(".")[-1]
if filetype not in ["png", "jpg", "jpeg"]:
continue
mtime = os.path.getmtime(path)
if RENAME_REGEX.match(os.path.basename(path)):
newBasename = f"Screenshot {datetime.datetime.fromtimestamp(mtime).strftime('%Y-%m-%d %H%M%S')}.{filetype}"
else:
newBasename = os.path.basename(path)
if time.time() - mtime < ARCHIVE_OLDNESS:
continue
subfolder = f"Screenshots {datetime.datetime.fromtimestamp(mtime).strftime('%Y-%m')}"
os.makedirs(os.path.join(SCREENSHOTS_DIR, subfolder), exist_ok=True)
os.rename(path, os.path.join(SCREENSHOTS_DIR, subfolder, newBasename))
if __name__ == "__main__":
logRun()
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment