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)