DEV Community

Stephen Wereko
Stephen Wereko

Posted on

πŸ“ Stop Messy Downloads Forever: Python Organizes Your Files Automatically βœ…

If your Downloads folder looks like a war zone 😭 (PDFs + images + zip files everywhere), you’re not alone.

So I built a beginner-friendly Python script that automatically:

βœ… Organizes files into folders (PDFs / Images / Docs / Zips / Videos / Sheets)
βœ… Creates a folder for today’s date (YYYY-MM-DD)
βœ… Renames every file with a timestamp (date/time)
βœ… Prevents overwriting duplicates (_1, _2, _3…)

Result: your Downloads folder becomes clean, sorted, and searchable βœ…

▢️ Video Tutorial (Silent Coding / No Talking)

I recorded a quick walkthrough showing the before β†’ code β†’ run β†’ after.

πŸ“Ί Watch it here: https://youtu.be/A3Yz100IbLw

(You can also check my channel: https://www.youtube.com/@CodeGees
)

Downloads/
Images/2026-01-16/2026-01-16_14-20-05_photo.png
PDFs/2026-01-16/2026-01-16_14-20-05_report.pdf
Zips/2026-01-16/2026-01-16_14-20-05_project.zip
import os
from datetime import datetime

βœ… Downloads folder

downloads_folder = os.path.join(os.path.expanduser("~"), "Downloads")

βœ… Today's date folder

today_date = datetime.now().strftime("%Y-%m-%d")

βœ… File categories

file_categories = {
"PDFs": (".pdf",),
"Images": (".png", ".jpg", ".jpeg", ".webp"),
"Docs": (".docx", ".txt"),
"Zips": (".zip", ".rar", ".7z"),
"Videos": (".mp4", ".mov"),
"Sheets": (".xlsx", ".csv"),
}

βœ… Loop through downloads

for filename in os.listdir(downloads_folder):
old_path = os.path.join(downloads_folder, filename)

# Skip folders
if os.path.isdir(old_path):
    continue

# Skip shortcuts/temp/system files
if filename.lower().endswith((".lnk", ".tmp", ".ini")):
    continue

# Find file extension
file_ext = os.path.splitext(filename)[1].lower()

# Pick category folder
category_name = next(
    (name for name, exts in file_categories.items() if file_ext in exts),
    "Other"
)

# Create target folder (type + date)
target_folder = os.path.join(downloads_folder, category_name, today_date)
os.makedirs(target_folder, exist_ok=True)

# Create timestamp rename
file_name, ext = os.path.splitext(filename)
timestamp = datetime.now().strftime("%Y-%m-%d_%H-%M-%S")
new_path = os.path.join(target_folder, f"{timestamp}_{file_name}{ext}")

# Avoid overwriting duplicates
counter = 1
while os.path.exists(new_path):
    new_path = os.path.join(target_folder, f"{timestamp}_{file_name}_{counter}{ext}")
    counter += 1

# Rename + move
os.rename(old_path, new_path)

print("βœ…", filename, "β†’", category_name)
Enter fullscreen mode Exit fullscreen mode

print("\nπŸŽ‰ Done! Downloads are now organized by type + date."

βœ… Try it Yourself

Save the file as: downloads_folder_organizer.py

Run it:
python downloads_folder_organizer.py

Top comments (0)