Batch Rename Files with CMD: The Complete Guide

Rename hundreds of files in seconds using Windows Command Prompt. Learn wildcards, patterns, and batch processing without installing any software.

Batch Rename Files with CMD: The Complete Guide
On this page
  1. Introduction
  2. Basic Rename (Single File)
  3. Batch Rename (Many Files)
  4. Advanced Patterns
  5. Troubleshooting
  6. FAQ

Introduction

TL;DR

Use ren *.jpg photo_*.jpg to add a prefix, or ren "old name.txt" "new name.txt" for single files.

You just downloaded 500 photos from your camera, and they're all named IMG_0001.jpg through IMG_0500.jpg. Not very helpful.

Renaming them one by one? That could take hours. Downloading fancy software? Overkill. The solution is already on your computer: Windows Command Prompt.

In this guide, you'll learn how to rename hundreds of files in seconds using simple CMD commands.

Basic Rename (Single File)

Before batch operations, let's master the basics. The ren (or rename) command changes a file's name.

Batch Rename Before and After Example

1Open CMD in Your Folder

Navigate to the folder containing your file. Click the address bar, type cmd, and press Enter.

2Run the Rename Command

Command Prompt
C:\Users\Photos>ren "old_photo.jpg" "vacation_2024.jpg"
C:\Users\Photos>
Pro Tip

Use quotes around filenames if they contain spaces. Without quotes, CMD treats each word as a separate argument.

Batch Rename (Many Files)

Now for the fun part: renaming multiple files at once using wildcards.

Add a Prefix to All Files

Want to add "project_" before every .txt file? Here's how:

Command Prompt
C:\Documents>for %f in (*.txt) do ren "%f" "project_%f"
report.txt → project_report.txt
notes.txt → project_notes.txt
data.txt → project_data.txt

Change File Extensions

Need to convert all .txt files to .md (Markdown)? Simple:

Command Prompt
C:\Notes>ren *.txt *.md
All .txt files are now .md files!

Replace Part of Filename

Unfortunately, CMD's ren can't do find-and-replace natively. For that, use PowerShell:

PowerShell
Get-ChildItem *.jpg | Rename-Item -NewName { $_.Name -replace "IMG_","vacation_" }
IMG_001.jpg → vacation_001.jpg

Advanced Patterns

Rename with Sequential Numbers

Create numbered files like photo_001.jpg, photo_002.jpg:

set n=1 & for %f in (*.jpg) do (ren "%f" "photo_!n!.jpg" & set /a n+=1)

* Run this in a .bat file or enable delayed expansion in CMD first.

Rename in Subfolders

To rename files in all subdirectories, use the /r switch with for:

for /r %f in (*.txt) do ren "%f" "backup_%~nxf"

Troubleshooting

"The syntax is incorrect"

You probably forgot quotes around filenames with spaces, or used the wrong slash. CMD uses backslash \, not forward slash.

"A duplicate file name exists"

Your rename pattern creates a name that already exists. Add unique prefixes or use numbered sequences.

"%f was unexpected"

In batch files (.bat), use %%f instead of %f. The double percent is required.

Frequently asked questions

Can I undo a batch rename?

No built-in undo exists. Always test on a copy of your files first, or back them up before running batch commands.

Does this work on Mac or Linux?

No, these are Windows commands. On Mac/Linux, use the "mv" command or tools like "rename" (Perl-based).

Can I preview changes before applying?

Yes! Replace "ren" with "echo" in your command. It will show what would happen without actually renaming.

How do I rename files with special characters?

Wrap filenames in double quotes. For files with quotes in the name, use escape characters or rename them manually first.

Keep reading

Create a Folder Structure Template with One CommandProductivity

Create a Folder Structure Template with One Command

Set up project directories instantly. Learn to create entire folder hierarchies with a single CMD command—perfect for developers and organized workflows.

MD Kawsar· January 18, 2026 · 4 min read
Delete Empty Folders in Seconds Using CMDProductivity

Delete Empty Folders in Seconds Using CMD

Clean up your file system by removing hundreds of empty folders instantly. A simple one-line command does the trick—no software needed.

MD Kawsar· January 18, 2026 · 3 min read
Find Large Files Eating Your Disk Space with CMDProductivity

Find Large Files Eating Your Disk Space with CMD

Discover which files are hogging your storage. Learn CMD and PowerShell commands to quickly find the biggest files on your computer without third-party tools.

MD Kawsar· January 18, 2026 · 4 min read

Want us to build this for you?

Tell us what data or workflow you need. We reply within a few hours.

Book a free call ↗