Featured Posts

Start Your Journey with Linux Command Line

Image
Start Your Journey with the Linux Command Line: A Comprehensive Guide Whether you are a software developer, system administrator, analytics engineer, or cybersecurity enthusiast, mastering the Linux command line (terminal) is one of the single most effective skills you can acquire. While graphical user interfaces (GUIs) offer visual convenience, the command line interface (CLI) delivers unmatched speed, fine-grained system control, and seamless automation capabilities. Linux Command Line This tutorial breaks down more than 35 core Linux commands into structured, practical modules complete with real-world examples, flags, and command-chaining techniques. By building muscle memory around these fundamentals, you will elevate your daily technical workflow from basic navigation to advanced command orchestration. Why Learn the Command Line? The Linux CLI is not merely a legacy tool—it remains the foundation of modern cloud architecture, server maintenance, DevOps pipelines, and enterp...

Python for Windows Beginners: Build Your First Automated Workflow in 10 Minutes

What You Will Build Today

Python automation on Windows
Organize your Downloads folder automatically with Python

If you are new to Windows, nothing feels better than watching your computer finish a boring task by itself. In this tutorial you will write a real Python program that cleans up your Downloads folder: every file is sorted into a sub-folder by its type, and an activity log is saved so you can see what changed. Best of all, take a few minutes today, and from tomorrow it runs with zero clicks.

The whole setup, from installing Python to scheduling the job, takes about ten minutes.

Step 1: Install Python on Windows

Before any automation, Python must be on your machine.

Download and run the installer

  1. Open python.org/downloads in your browser.
  2. Click the big Download Python button. The page detects Windows automatically and offers the latest stable version.
  3. Run the downloaded .exe file.

Tick the two important boxes

On the first screen of the installer, tick these checkboxes before clicking Install Now:

  • Install launcher for all users (recommended)
  • Add Python to PATH (required)

The second checkbox is the one most beginners miss. If Python is not on the PATH, Windows cannot find the python command when you type it.

Verify the installation

Open Command Prompt (press Windows + R, type cmd, press Enter) and run:

python --version

If that prints nothing, try the Windows launcher instead:

py --version

Seeing a line like Python 3.13.2 means everything is installed correctly.

Step 2: Create a Folder for Your Project

Good projects live in their own folder. Create one called automation:

cd %USERPROFILE%
mkdir automation
cd automation

Every script you build in this series will live here, which keeps things tidy and easy to find.

Step 3: Write Your First Automation Script

Create a new text file named organize_downloads.py inside automation. Open it in Notepad and copy this in:

import os
import shutil
from datetime import datetime

# 1. Point at the Downloads folder of the current user
source = os.path.join(os.environ["USERPROFILE"], "Downloads")

# 2. Map common extensions to tidy sub-folder names
groups = {
    "Images": (".jpg", ".jpeg", ".png", ".gif", ".webp"),
    "Documents": (".pdf", ".docx", ".xlsx", ".txt", ".md"),
    "Archives": (".zip", ".rar", ".7z", ".tar", ".gz"),
    "Videos": (".mp4", ".mov", ".avi", ".mkv"),
    "Music": (".mp3", ".wav", ".flac", ".m4a"),
}

log = []

# 3. Walk every file in Downloads (no sub-folder recursion)
for name in os.listdir(source):
    path = os.path.join(source, name)
    if os.path.isdir(path):
        continue  # skip folders, only sort loose files

    ext = os.path.splitext(name)[1].lower()
    dest_dir = "Other"  # anything without a matching group
    for folder, exts in groups.items():
        if ext in exts:
            dest_dir = folder
            break

    # 4. Create the group folder if it does not exist yet
    os.makedirs(os.path.join(source, dest_dir), exist_ok=True)

    # 5. Move the file and record what happened
    destination = os.path.join(source, dest_dir, name)
    shutil.move(path, destination)
    log.append(f"Moved {name} -> {dest_dir}")

# 6. Write a timestamped report file so you can audit the run
report = os.path.join(source, "organize_report.txt")
with open(report, "a", encoding="utf-8") as f:
    f.write(f"\n--- Run {datetime.now().isoformat()} ---\n")
    f.write("\n".join(log) if log else "Nothing to organize.")

print(f"Done. {len(log)} file(s) moved. Report saved to {report}.")

How the script works

The program follows a simple plan:

  • It computes the location of your Downloads folder with os.environ.
  • A dictionary maps file extensions to tidy group names such as Documents and Archives.
  • Every loose file is moved into its matching group folder.
  • A running log is appended to organize_report.txt, timestamped with the current date and time.

Each line in the code has a short inline comment, so even if you have never read Python before, you can follow the logic line by line.

Step 4: Test the Script Manually

Run the automation once by hand to confirm it works:

cd %USERPROFILE%\automation
python organize_downloads.py

Check your Downloads folder. Loose files should now be grouped, and organize_report.txt should list what moved. If you see an error about python not being recognized, go back to Step 1 and confirm the Add Python to PATH checkbox.

Step 5: Make It Run Automatically

Now the fun part: software that runs itself.

Option A: Scheduled task (best)

The Windows Task Scheduler runs your script on a schedule even when you are logged out:

schtasks /Create /TN "Organize Downloads" /TR "python %USERPROFILE%\automation\organize_downloads.py" /SC DAILY /ST 09:00 /F

Run that from an Administrator Command Prompt. The task runs every day at 9:00 AM.

Option B: Python double-click convention

You can also run the script by double-clicking it in File Explorer. Add this line to the very end so the window stays open after the work finishes:

input("Press Enter to close...")

Double-clicking a .py file on Windows launches it with the Python runtime directly; this is a great way to run a script when you are at the keyboard.

Option C: Wake up at boot

To run the script every time you sign in instead of on a fixed clock, add a shortcut to the script inside the Startup folder:

explorer shell:startup

Drop a shortcut to organize_downloads.py into that window and it will run at every login.

Key Takeaways

  • Tick Add Python to PATH during installation, or python simply will not work in the terminal.
  • One script, one folder: keep every automation inside automation so you always know where it lives.
  • Small building blocks with inline comments are easy to extend. Change the groups dictionary to sort any file type you like.
  • schtasks gives you unattended scheduling; the Startup folder gives you per-login execution.

To go further, try adding rules for email drafts, renaming files by date, or backing up a folder to a second drive. The same pattern applies to all of them.

Want More Hands-On Python Automation?

If this workflow helped you, you will love the full series. Subscribe to @CodeSecureTech and follow my Facebook page for more hands-on Python automation tutorials, scripts you can copy, and Windows tips that save real time. New workflows drop regularly, so join now and never miss one.

Comments

Popular Posts

PROJECT MAVEN | The Architecture of Algorithmic Warfare

Open Source: The Invisible Engine of Your Daily Life

Data Analysis Roadmap 2026: From Excel Lover to Python-Powered Analyst

How to Deactivate Screen Reader in Kali Linux

Convert a Currency Number to Words in Excel