My Downloads folder had 1,400 files in it.
PDFs mixed with screenshots, ZIP files buried under random .tmp files, video clips I downloaded once and forgot about. Every time I needed something, it took me five minutes of scrolling to find it.
So I wrote a Python script to fix it. It took about 20 minutes to write, and now I run it whenever things get messy.
Here's exactly how it works — and the full code you can copy.
What the script does
It scans a folder you choose, looks at each file's extension, and moves it into a sub-folder based on its type:
The full code
No external libraries needed — this runs on any Python 3 installation.
import os
import shutil
FOLDER = os.path.expanduser("~/Downloads")
CATEGORIES = {
"Images": [".jpg", ".jpeg", ".png", ".gif", ".bmp", ".svg", ".webp"],
"Videos": [".mp4", ".mov", ".avi", ".mkv", ".wmv"],
"Audio": [".mp3", ".wav", ".flac", ".aac", ".ogg"],
"Documents": [".pdf", ".docx", ".doc", ".txt", ".xlsx", ".pptx", ".csv"],
"Archives": [".zip", ".rar", ".tar", ".gz", ".7z"],
"Code": [".py", ".js", ".html", ".css", ".json", ".xml"],
"Others": [],
}
def get_category(extension):
for category, extensions in CATEGORIES.items():
if extension.lower() in extensions:
return category
return "Others"
def organise_folder(folder_path):
moved = 0
for filename in os.listdir(folder_path):
filepath = os.path.join(folder_path, filename)
if os.path.isdir(filepath):
continue
_, ext = os.path.splitext(filename)
category = get_category(ext)
dest_folder = os.path.join(folder_path, category)
os.makedirs(dest_folder, exist_ok=True)
dest_path = os.path.join(dest_folder, filename)
shutil.move(filepath, dest_path)
print(f"Moved: {filename} → {category}/")
moved += 1
print(f"\nDone! {moved} file(s) organised.")
organise_folder(FOLDER)
How to run it
1. Check Python is installed
python --version
2. Save the script as organizer.py
3. Change the folder path if needed
Customising it
Add your own categories:
"Design": [".psd", ".ai", ".xd", ".fig"],
"Ebooks": [".epub", ".mobi"],
Run on multiple folders:
folders = [
os.path.expanduser("~/Downloads"),
os.path.expanduser("~/Desktop"),
]
for folder in folders:
organise_folder(folder)
Why I love scripts like this
This script won't change your life. But it's a perfect example of what Python is great at: small, specific problems that quietly eat your time.
Once you understand how this one works, you start seeing automation opportunities everywhere — renaming files, sending reports by email, cleaning up spreadsheets. The pattern is always the same: find the repetitive thing, write 30 lines, never do it manually again.
If you want 9 more scripts like this one — bulk file renamer, password generator, PDF merger, web scraper, and more — I put them all together in a short e-book with full commented code and step-by-step instructions.
👉 10 Python Scripts for Everyday Life
Every script works out of the box. No advanced Python required.
What repetitive task would you automate first? Drop it in the comments!
FOLDER = "C:/Users/YourName/Desktop" # Windows
FOLDER = "/home/yourname/Desktop" # Mac / Linux
4. Run it
python organizer.py
Top comments (0)