If you’re like me, your Downloads folder is where files go to disappear. PDFs, images, .zip files, random installers all dumped into a digital junk drawer. Every few weeks, I’d waste an hour “cleaning up.”
So, I decided to stop playing janitor. Instead, I wrote a Python script that auto-organizes my Downloads folder every time I add a new file. Now, PDFs go to “Documents,” images to “Pictures,” videos to “Media,” and even code files into a “Projects” folder.
No clicks. No dragging. No excuses.
Step 1: The Core Idea
The goal was simple:
- Watch the Downloads folder.
- When a new file arrives, move it into the correct folder.
- Organize by file type (and optionally by date).
Instead of manually sorting files, I wanted my laptop to behave like a neat freak roommate.
Step 2: The Code
Here’s the full script I still run on my machine:
import os
import shutil
from watchdog.observers import Observer
from watchdog.events import FileSystemEventHandler
# Set up folders
DOWNLOADS = "/Users/yourname/Downloads"
DESTINATIONS = {
"Documents": [".pdf", ".docx", ".txt"],
"Pictures": [".jpg", ".jpeg", ".png", ".gif"],
"Media": [".mp4", ".mp3", ".mkv"],
"Projects": [".py", ".ipynb", ".js", ".html", ".css"],
"Archives": [".zip", ".rar", ".tar", ".gz"],
}
class FileMover(FileSystemEventHandler):
def on_modified(self, event):
for filename in os.listdir(DOWNLOADS):
src = os.path.join(DOWNLOADS, filename)
if os.path.isfile(src):
ext = os.path.splitext(filename)[1].lower()
for folder, extensions in DESTINATIONS.items():
if ext in extensions:
dest_folder = os.path.join(DOWNLOADS, folder)
os.makedirs(dest_folder, exist_ok=True)
shutil.move(src, os.path.join(dest_folder, filename))
print(f"Moved: {filename} → {folder}")
# Run the watcher
event_handler = FileMover()
observer = Observer()
observer.schedule(event_handler, DOWNLOADS, recursive=False)
observer.start()
try:
while True:
pass
except KeyboardInterrupt:
observer.stop()
observer.join()
Step 3: How It Works
- I used the
watchdog
library to monitor folder changes in real-time. - When a new file is detected, the script checks its extension.
- It matches the extension to a destination folder (like “Pictures” or “Archives”).
- the destination folder doesn’t exist, Python creates it
- The file is moved automatically.
That’s it. A digital Marie Kondo for files.
Step 4: Taking It Further
After running this for a week, I extended it:
Date-based subfolders:
from datetime import datetime today = datetime.now().strftime("%Y-%m-%d") dest_folder = os.path.join(DOWNLOADS, folder, today)
- Now, all files are organized not just by type, but by the day I downloaded them.
- Cloud Sync: I set some categories (like “Projects”) to auto-sync with my GitHub repos or Google Drive.
- Smart Filtering: With
mimetypes
, I added handling for less obvious file types (like JSON, CSV, SQL dumps).
Step 5: Why Not Just Use Finder or Explorer?
Sure, Windows and macOS both let you sort and search files. But:
- They don’t auto-file things for you.
- They don’t create date-stamped subfolders.
- They don’t send your project files to GitHub automatically.
This script turned my Downloads from a landfill into a well-organized digital library.
Step 6: Deployment
I didn’t want to run the script manually, so I:
- Set it up as a background process using
launchd
(macOS) or Task Scheduler (Windows). - Alternatively, used a systemd service on Linux.
Now it runs 24/7 — silently cleaning up after me.
Why This Matters
This might feel like a “small” automation. But here’s the truth: small daily friction kills productivity. Every second I used to waste digging through Downloads is now saved. Over months, that’s hours of regained focus.
And the best part? My digital life now sparks joy.
Learn more The Python Script That Organizes My Downloads Folder Better Than I Ever Could