惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Hugging Face - Blog
Hugging Face - Blog
Vercel News
Vercel News
C
Check Point Blog
G
Google Developers Blog
博客园 - 司徒正美
量子位
Engineering at Meta
Engineering at Meta
S
SegmentFault 最新的问题
Google DeepMind News
Google DeepMind News
F
Fortinet All Blogs
A
About on SuperTechFans
美团技术团队
D
DataBreaches.Net
Stack Overflow Blog
Stack Overflow Blog
Jina AI
Jina AI
Y
Y Combinator Blog
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Apple Machine Learning Research
Apple Machine Learning Research
J
Java Code Geeks
MongoDB | Blog
MongoDB | Blog
人人都是产品经理
人人都是产品经理
H
Hackread – Cybersecurity News, Data Breaches, AI and More
The Cloudflare Blog
U
Unit 42

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant
I Built a Python Script That Cleans My Downloads Folder A...
João Paulo Gomes · 2026-06-06 · via DEV Community

João Paulo Gomes

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