Every automation journey starts with one annoying, repetitive task. For most of us, it's the Downloads folder: PDFs, screenshots, zip files and installers all piled into one place. Let's fix that with a short Python script.
What we're building
A script that scans your Downloads folder and moves each file into a sub-folder based on its type: Images, Documents, Archives and so on.
The script
from pathlib import Path
import shutil
DOWNLOADS = Path.home() / "Downloads"
GROUPS = {
"Images": {".png", ".jpg", ".jpeg", ".gif", ".webp"},
"Documents": {".pdf", ".docx", ".xlsx", ".pptx", ".txt"},
"Archives": {".zip", ".rar", ".7z", ".tar", ".gz"},
"Installers":{".exe", ".msi", ".dmg", ".pkg"},
}
for item in DOWNLOADS.iterdir():
if not item.is_file():
continue
for folder, exts in GROUPS.items():
if item.suffix.lower() in exts:
target = DOWNLOADS / folder
target.mkdir(exist_ok=True)
shutil.move(str(item), target / item.name)
print(f"Moved {item.name} -> {folder}")
break
How it works
- pathlib gives us a clean way to work with folders on any operating system.
- GROUPS maps a folder name to the file extensions that belong in it. Add your own.
- The loop checks each file's extension and moves it into the matching folder, creating the folder if needed.
Tip: run it once by hand first and watch the output. Once you trust it, schedule it.
Make it run on its own
On Windows, use Task Scheduler to run python tidy.py every evening. On macOS or Linux, a one-line cron entry does the same job. That's the moment a script becomes an automation: it works while you don't.
What's next
Once this clicks, the same pattern (find files → decide → act) can rename invoices, back up folders, or resize images in bulk. I'll cover those in upcoming posts.