cd /news/developer-tools/bulk-rename-files-from-the-command-l… · home topics developer-tools article
[ARTICLE · art-13194] src=dev.to ↗ pub= topic=developer-tools verified=true sentiment=· neutral

Bulk Rename Files from the Command Line with Python

This article explains how to rename multiple files from the command line using a simple Python script. The provided script uses the `os` and `sys` modules to iterate through files in a directory, adding a specified prefix to each filename. It also mentions a more advanced tool called Bulk Renamer Pro, which is built with Python 3 and has no external dependencies.

read1 min views24 publishedMay 24, 2026

Renaming hundreds of files manually is tedious. Here is how to do it with a simple Python script.

The Problem #

You have a folder full of photos and you need to add prefixes, change extensions, or convert case.

Quick Solution #

import os, sys

def rename_files(directory, prefix=""):
    for f in os.listdir(directory):
        fp = os.path.join(directory, f)
        if not os.path.isfile(fp): continue
        name, ext = os.path.splitext(f)
        new_path = os.path.join(directory, prefix + name + ext)
        print(f"{f} -> {os.path.basename(new_path)}")

if __name__ == "__main__":
    rename_files(sys.argv[1], sys.argv[2] if len(sys.argv) > 2 else "")
python renamer.py ./photos vacation_

This adds a prefix to every file in the directory.

Advanced Features #

The full CLI tool (Bulk Renamer Pro) adds:

  • Regex find-and-replace
  • Case conversion
  • Auto-numbering
  • Extension filtering
  • Recursive scanning
  • Safe dry-run mode

Why CLI? #

  • Fast: one command, hundreds of files
  • Repeatable: same result every time
  • Scriptable: chain with other commands

Built with Python 3. No external dependencies.

── more in #developer-tools 4 stories · sorted by recency
── more on @python 3 stories trending now
sponsored brought to you by zahid.host 4,200+ EU-deployed projects
reading about agents? ship yours in a single git push.

Run your AI side-project on zahid.host

EU-based hosting, git-push deploys, automatic HTTPS, no cold starts. Free tier with a custom domain — perfect for shipping the agent you just read about.

$git push zahid main
Live at https://your-agent.zahid.host
Get free account → Pricing
from €0/mo · no card required
LIVE [news/bulk-rename-files-fr…] indexed:0 read:1min 2026-05-24 ·