DEV Community

info_brust
info_brust

Posted on

πŸš€ How I Built My First Python Automation Script (And You Can Too!) Hey devs! πŸ‘‹

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
Enter fullscreen mode Exit fullscreen mode

🚧 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)