I Built a Python Bot That Organizes My Desktop Every Night So I Can Be Lazy πŸ˜ŽπŸ“

Let’s be honest:
My desktop was a digital jungle β€” screenshots, PDFs, memes, random .zip files from 2019…

So I did what any lazy but efficient developer would do:

I built a Python script that automatically organizes my desktop every night at 11:59 …


This content originally appeared on DEV Community and was authored by Nishkarsh Pandey

Let’s be honest:
My desktop was a digital jungle β€” screenshots, PDFs, memes, random .zip files from 2019...

So I did what any lazy but efficient developer would do:

I built a Python script that automatically organizes my desktop every night at 11:59 PM.
It sorts files into folders like Images, Docs, Zips, etc.

Now, my desktop stays clean, and I don’t lift a finger. πŸ’…

🧠 How It Works
The script scans your desktop.
It looks at file extensions.
It moves files into categorized folders.
It can run every night using a scheduled task (Windows Task Scheduler / cron on macOS/Linux).

🐍 The Python Code:

import os
import shutil
from pathlib import Path

# Set your desktop path
desktop = Path.home() / "Desktop"

# File categories
categories = {
    "Images": [".jpg", ".jpeg", ".png", ".gif"],
    "Documents": [".pdf", ".docx", ".txt"],
    "Zips": [".zip", ".rar"],
    "Code": [".py", ".js", ".html"],
    "Videos": [".mp4", ".mov"],
    "Others": []
}

def organize():
    for file in desktop.iterdir():
        if file.is_file():
            moved = False
            for folder, extensions in categories.items():
                if file.suffix.lower() in extensions:
                    move_file(file, desktop / folder)
                    moved = True
                    break
            if not moved:
                move_file(file, desktop / "Others")

def move_file(file, destination):
    destination.mkdir(exist_ok=True)
    shutil.move(str(file), str(destination / file.name))
    print(f"Moved: {file.name} β†’ {destination}")

if __name__ == "__main__":
    organize()

πŸ• How to Run It Automatically
πŸͺŸ Windows:
Open Task Scheduler.
Create a new task.
Set a daily trigger (e.g., 11:59 PM)

Action:
Program/script: python
Add arguments: C:\path\to\desktop_organizer.py

🍎 macOS/Linux:
Add this to your crontab:

59 23 * * * /usr/bin/python3 /path/to/desktop_organizer.py

πŸ’Ύ GitHub Repo:
Nish2005karsh

πŸŽ‰ The Result?
Every night my desktop gets cleaned like magic β€” no guilt, no manual work.

Lazy? Maybe.
Efficient? Definitely.

πŸ’¬ What Should I Build Next?
Got a cool automation idea?
Want this to also auto-delete screenshots or organize by date?

Drop it in the comments πŸ‘‡ and I’ll try building it next!


This content originally appeared on DEV Community and was authored by Nishkarsh Pandey


Print Share Comment Cite Upload Translate Updates
APA

Nishkarsh Pandey | Sciencx (2025-05-22T16:32:52+00:00) I Built a Python Bot That Organizes My Desktop Every Night So I Can Be Lazy πŸ˜ŽπŸ“. Retrieved from https://www.scien.cx/2025/05/22/i-built-a-python-bot-that-organizes-my-desktop-every-night-so-i-can-be-lazy-%f0%9f%98%8e%f0%9f%93%81/

MLA
" » I Built a Python Bot That Organizes My Desktop Every Night So I Can Be Lazy πŸ˜ŽπŸ“." Nishkarsh Pandey | Sciencx - Thursday May 22, 2025, https://www.scien.cx/2025/05/22/i-built-a-python-bot-that-organizes-my-desktop-every-night-so-i-can-be-lazy-%f0%9f%98%8e%f0%9f%93%81/
HARVARD
Nishkarsh Pandey | Sciencx Thursday May 22, 2025 » I Built a Python Bot That Organizes My Desktop Every Night So I Can Be Lazy πŸ˜ŽπŸ“., viewed ,<https://www.scien.cx/2025/05/22/i-built-a-python-bot-that-organizes-my-desktop-every-night-so-i-can-be-lazy-%f0%9f%98%8e%f0%9f%93%81/>
VANCOUVER
Nishkarsh Pandey | Sciencx - » I Built a Python Bot That Organizes My Desktop Every Night So I Can Be Lazy πŸ˜ŽπŸ“. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2025/05/22/i-built-a-python-bot-that-organizes-my-desktop-every-night-so-i-can-be-lazy-%f0%9f%98%8e%f0%9f%93%81/
CHICAGO
" » I Built a Python Bot That Organizes My Desktop Every Night So I Can Be Lazy πŸ˜ŽπŸ“." Nishkarsh Pandey | Sciencx - Accessed . https://www.scien.cx/2025/05/22/i-built-a-python-bot-that-organizes-my-desktop-every-night-so-i-can-be-lazy-%f0%9f%98%8e%f0%9f%93%81/
IEEE
" » I Built a Python Bot That Organizes My Desktop Every Night So I Can Be Lazy πŸ˜ŽπŸ“." Nishkarsh Pandey | Sciencx [Online]. Available: https://www.scien.cx/2025/05/22/i-built-a-python-bot-that-organizes-my-desktop-every-night-so-i-can-be-lazy-%f0%9f%98%8e%f0%9f%93%81/. [Accessed: ]
rf:citation
» I Built a Python Bot That Organizes My Desktop Every Night So I Can Be Lazy πŸ˜ŽπŸ“ | Nishkarsh Pandey | Sciencx | https://www.scien.cx/2025/05/22/i-built-a-python-bot-that-organizes-my-desktop-every-night-so-i-can-be-lazy-%f0%9f%98%8e%f0%9f%93%81/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.