Python Automation: 5 Scripts That Save You Time
Five short Python scripts for everyday jobs: tidy your Downloads, rename photos, total the day's sales, back up a folder and find big files. Real output included.

Every week you probably do the same boring jobs on your computer: tidying a messy Downloads folder, renaming photos one by one, adding up the shop's sales in a calculator, copying your notes somewhere safe. Each job takes ten minutes. Python can do each one in a second, every time, without mistakes.
Here are five short scripts you can use today. Each one uses only Python's standard library, so there's nothing to install apart from Python itself. They're short enough to read in a minute and change for your own needs.
Before you start
You need Python 3 on your computer. (No Python yet? Follow How to Install Python on Your Computer first.) Save each script as a .py file and run it from a terminal, such as python tidy.py Downloads.
We ran every script below for real, on sample folders in C:\Users\you, and the output shown is what came out. One rule before anything else: a script can mess up 300 files as fast as it fixes them. Try it on a copy of a folder first, and let it show you what it would do before it does it. The first two scripts work that way.
1. Tidy your Downloads folder
This script sorts files into subfolders by their type. It uses argparse to read the folder name from the command line, and it only moves anything when you add --go:
import argparse
import shutil
from pathlib import Path
KINDS = {
".pdf": "Documents", ".docx": "Documents", ".xlsx": "Documents",
".jpg": "Photos", ".jpeg": "Photos", ".png": "Photos",
".mp3": "Music", ".mp4": "Videos", ".zip": "Archives",
}
parser = argparse.ArgumentParser(description="Sort a folder into subfolders by file type.")
parser.add_argument("folder")
parser.add_argument("--go", action="store_true", help="really move the files")
args = parser.parse_args()
folder = Path(args.folder)
for f in sorted(folder.iterdir()):
kind = KINDS.get(f.suffix.lower())
if not f.is_file() or kind is None:
continue
if args.go:
(folder / kind).mkdir(exist_ok=True)
shutil.move(f, folder / kind / f.name)
print(f"moved {f.name} -> {kind}/")
else:
print(f"would move {f.name} -> {kind}/")
Run python tidy.py Downloads first:
would move budget.xlsx -> Documents/
would move CV_Ama.docx -> Documents/
would move highlife-mix.mp3 -> Music/
would move IMG_0412.JPG -> Photos/
would move lecture-3.mp4 -> Videos/
would move photos-from-church.zip -> Archives/
would move school-fees-receipt.pdf -> Documents/
would move screenshot.png -> Photos/
Happy with the plan? Run python tidy.py Downloads --go and the files really move. suffix.lower() treats .JPG like .jpg, and types the script doesn't know (like setup.exe) are left where they are. As a bonus, argparse gives you a help page for free with python tidy.py --help:
usage: tidy.py [-h] [--go] folder
Sort a folder into subfolders by file type.
positional arguments:
folder
options:
-h, --help show this help message and exit
--go really move the files
2. Rename a folder of photos
Phone photos come with names like IMG_2041.JPG. This script numbers them in order, as kumasi_001.jpg, kumasi_002.jpg and so on. It reads the folder and the new name from sys.argv, the simplest way to get command-line values:
import sys
from pathlib import Path
folder = Path(sys.argv[1])
prefix = sys.argv[2] # for example "kumasi"
go = "--go" in sys.argv
photos = sorted(p for p in folder.iterdir() if p.suffix.lower() in (".jpg", ".jpeg"))
for n, old in enumerate(photos, start=1):
new = folder / f"{prefix}_{n:03}.jpg"
if go:
old.rename(new)
print(f"{'renamed' if go else 'would rename'} {old.name} -> {new.name}")
Running python rename_photos.py Pictures\kumasi-trip kumasi shows the plan:
would rename IMG_2039.jpg -> kumasi_001.jpg
would rename IMG_2040.jpeg -> kumasi_002.jpg
would rename IMG_2041.JPG -> kumasi_003.jpg
would rename IMG_2042.jpg -> kumasi_004.jpg
Add --go to do it. {n:03} pads the number with zeros, so kumasi_002 sorts before kumasi_010. A notes.txt in the same folder was ignored, because only JPEGs are picked. Renaming has no undo button, which is exactly why the dry run comes first.
3. Add up the day's sales
Many small shops keep sales in a spreadsheet. Save it as a CSV file (in Excel or Google Sheets, choose CSV when you save or download) with columns item, qty and price, and this script totals each item, biggest first:
import csv
import sys
totals = {}
with open(sys.argv[1], newline="", encoding="utf-8") as f:
for row in csv.DictReader(f):
amount = int(row["qty"]) * float(row["price"])
totals[row["item"]] = totals.get(row["item"], 0) + amount
print("Sales today")
for item, total in sorted(totals.items(), key=lambda pair: pair[1], reverse=True):
print(f" {item:<12} GHS {total:>8.2f}")
print(f" {'TOTAL':<12} GHS {sum(totals.values()):>8.2f}")
With a small sales.csv of six sales, python sales_report.py sales.csv prints:
Sales today
rice 5kg GHS 720.00
cooking oil GHS 273.00
sugar GHS 252.00
milo tin GHS 190.00
TOTAL GHS 1435.00
csv.DictReader gives you each row as a dictionary, so you can use column names instead of positions. totals.get(item, 0) starts each new item at zero. The :<12 and :>8.2f parts line the columns up and show two decimal places.
4. Back up a folder into a dated zip
Your notes, your project, your CV: if the laptop dies, are they safe? This script packs a whole folder into one zip file with today's date in its name, ready to copy to a flash drive or upload when you're on Wi-Fi:
import shutil
import sys
from datetime import date
from pathlib import Path
source = Path(sys.argv[1])
backups = Path(sys.argv[2])
backups.mkdir(exist_ok=True)
name = backups / f"{source.name}-{date.today():%Y-%m-%d}"
archive = Path(shutil.make_archive(str(name), "zip", root_dir=source))
files = sum(1 for p in source.rglob("*") if p.is_file())
print(f"Saved {archive.name}: {files} files, {archive.stat().st_size:,} bytes")
python backup.py Documents\notes backups printed:
Saved notes-2026-11-27.zip: 3 files, 524 bytes
Your date and size will be different. shutil.make_archive does all the zipping, including subfolders, in one line. Because the date is in the name, each day's backup sits next to the last one instead of replacing it.
5. Find what's eating your storage
"Storage almost full" again? This script lists the biggest files in a folder and all its subfolders:
import sys
from pathlib import Path
folder = Path(sys.argv[1])
files = [p for p in folder.rglob("*") if p.is_file()]
files.sort(key=lambda p: p.stat().st_size, reverse=True)
total = sum(p.stat().st_size for p in files)
print(f"{len(files)} files, {total / 1_000_000:.1f} MB in all. Biggest:")
for p in files[:5]:
print(f" {p.stat().st_size / 1_000_000:7.1f} MB {p.relative_to(folder).as_posix()}")
On our tidied sample Downloads folder, python big_files.py Downloads found:
9 files, 268.7 MB in all. Biggest:
152.0 MB Videos/lecture-3.mp4
64.0 MB setup.exe
41.0 MB Archives/photos-from-church.zip
8.7 MB Music/highlife-mix.mp3
2.4 MB Photos/IMG_0412.JPG
rglob("*") walks through every subfolder, and sorting by st_size puts the biggest first. Notice the script only lists files. Deciding what to delete is still your job, and it's safer that way: Python's delete functions skip the Recycle Bin.
Make them run on their own
A script you have to remember to run is only half automated. Windows' Task Scheduler (or cron on macOS and Linux) can start the backup script every evening or the tidy script every morning. Use full paths in the task, because a scheduled script doesn't start in your usual folder. Swap print for the logging module and write to a file, so you can check the next day what happened.
Where to go next
These five scripts use a handful of tools again and again: pathlib for paths, shutil for copying and moving, csv for spreadsheets, and command-line arguments. Once you know them, you'll start spotting jobs to automate everywhere.
- Python Beyond the Basics teaches all of it step by step: working with files and CSV, automating everyday tasks,
argparse, logging, running scripts on a schedule, talking to APIs and a first taste of data. - Python Crash Course is the place to start if loops, lists, dictionaries and functions are still new. It runs entirely in your browser, so there's nothing to install while you learn.
Comments
Log in to join the conversation.
Loading comments...


