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)