Learn & Build

Practical Programming Tutorials & Projects

A Simple Python Script to Automate Daily Tasks

When learning programming, small practical scripts are often more useful than complex projects.

In this post, I’ll walk through a simple Python script that automates a common task:
organizing files into folders based on their type.

This is a great beginner exercise and shows how Python can be useful immediately.


What This Script Does

The script will:

  • Scan a folder
  • Detect file types (e.g. .txt, .jpg, .pdf)
  • Create folders automatically
  • Move files into the correct folder

The Python Script

import os
import shutil

source_folder = "files"

for filename in os.listdir(source_folder):
file_path = os.path.join(source_folder, filename)

if os.path.isfile(file_path):
    extension = filename.split(".")[-1]
    folder_name = extension.upper() + "_files"

    folder_path = os.path.join(source_folder, folder_name)
    os.makedirs(folder_path, exist_ok=True)

    shutil.move(file_path, folder_path)

How It Works (Simple Explanation)

  • os.listdir() reads all files in a folder
  • os.makedirs() creates folders if they don’t exist
  • shutil.move() moves files automatically

No external libraries are required.


Why This Is a Good Learning Project

  • You practice file handling
  • You learn basic automation
  • You see immediate results
  • You can extend it easily (dates, sizes, logs)

What I’ll Build Next

In the next posts, I’ll:

  • Improve this script
  • Add logging
  • Turn it into a reusable tool
  • Explore simple DevOps-style automation

Leave a comment

Navigation

About

Learn & Build is a personal blog about learning programming by building real projects. It documents practical tutorials, small experiments, and lessons learned along the way.