Hey devs! π
I've recently started diving into Python automation, and I wanted to share my experience building my very first script. Whether you're new to Python or just looking for a fun weekend project, this oneβs for you!
π οΈ The Idea
I wanted something useful but simpleβso I created a script that automatically organizes files in my Downloads folder based on file type. Think .pdf files go to a βDocsβ folder, .jpg to βImagesβ, etc.
π¦ Tech Stack
-Python 3.10
-os and shutil modules
-Runs on any OS (tested on Windows and Linux)
π§ What I Learned
Working with file paths and directories using os
Using shutil.move() to transfer files
Writing clean and modular code
Running scripts on a schedule with Task Scheduler / Cron Jobs
π‘ Code Snippet
import os
import shutil
DOWNLOADS = "/home/user/Downloads"
DESTINATIONS = {
"Images": [".png", ".jpg", ".jpeg", ".gif"],
"Docs": [".pdf", ".docx", ".txt"],
"Videos": [".mp4", ".mov"],
}
for filename in os.listdir(DOWNLOADS):
file_path = os.path.join(DOWNLOADS, filename)
if os.path.isfile(file_path):
for folder, extensions in DESTINATIONS.items():
if filename.lower().endswith(tuple(extensions)):
target_folder = os.path.join(DOWNLOADS, folder)
os.makedirs(target_folder, exist_ok=True)
shutil.move(file_path, os.path.join(target_folder, filename))
print(f"Moved {filename} to {folder}")
break
π§ What's Next?
I'm planning to add a GUI using Tkinter and maybe even turn it into a desktop app. Eventually, Iβd love to package it and share it with non-dev friends too.
β¨ Final Thoughts
Small projects like this are perfect for sharpening your skills and building confidence. If you're learning Python, I highly recommend picking something you're slightly annoyed with and automating it!
Let me know what you're working on in the comments. π¬
Feel free to fork or build on the projectβI'm always open to feedback!
Happy coding! ππ»
Top comments (0)