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

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/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.