Bulk & Automation

Rename Multiple Files From the Command Prompt (CMD)

The Windows command prompt renames files with one command, ren, and a couple of loop constructs. It's fast, it's built into every Windows machine, and for wildcard renames and simple prefixes it's all you need, no downloads, no scripting language to learn. This guide covers ren with wildcards, for loops for batch renaming, sequential numbering with a counter, and how to save the whole thing as a reusable .bat file. It also flags CMD's one real limit, no regular expressions, and where to go when you hit it.

The CMD Renaming Toolkit

CMD keeps it simple: one command, two loop forms, and a script file to make it repeatable.

TaskConstructNotes
Rename one file or by wildcardren old.txt new.txtWildcards allowed on both sides
Loop over matching filesfor %f in (*.ext) do ...Double the % to %%f inside a .bat
Sequential numberingfor /f with a counterNeeds delayed expansion in a script
Make it reusableSave as a .bat fileRun the same rename anytime
Pattern / regex renameNot supportedUse PowerShell instead

Method 1: The ren Command With Wildcards

ren (short for rename) is the whole foundation. For one file: ren oldname.txt newname.txt. Its useful trick is wildcards, which let one command touch many files. ren *.jpeg *.jpg changes the extension of every .jpeg file in the current folder to .jpg. ren report*.txt draft*.txt renames report1.txt to draft1.txt, report2.txt to draft2.txt, and so on, the wildcard positions are matched between the two names.

The ? wildcard matches a single character, which helps with fixed-width names. ren is genuinely powerful for these positional wildcard renames, but it can't insert text at an arbitrary position or transform names conditionally, which is where the loop comes in.

Two quirks catch people out. ren keeps every file in its current folder and cannot move anything, so both the old and new names have to point at the same directory. It also refuses to overwrite a file that already exists, if new.txt is already there the command fails instead of replacing it, which is a safe default but means you occasionally have to clear or rename the target first before ren will accept the new name.

Method 2: A for Loop to Rename a Batch

When you need to do something to each file rather than a single wildcard swap, loop over them. Straight from the command prompt, use a single %: for %f in (*.txt) do ren "%f" "new-%f". That prefixes every .txt file with new-. Inside a .bat script you must double the percent sign, %%f, or the script won't parse:

  1. Open a new text file and add: @echo off
  2. Add the loop: for %%f in (*.txt) do ren "%%f" "archived_%%f"
  3. Save it with a .bat extension, for example rename-files.bat.
  4. Double-click it, or run it from CMD, to apply the rename to the folder it sits in.

Method 3: Sequential Numbering With for /f

It helps to understand why plain ren cannot do this by itself. Wildcards only match positions between two names and carry across whatever character was already sitting there, they never generate fresh text, so there is no wildcard that means give each file the next number in sequence. That counting has to come from somewhere, and in CMD the only place it can come from is a loop that walks the files one at a time while a variable ticks upward. That is the whole reason numbering forces you into a for loop and a counter rather than a single ren line.

Numbering files in order needs a counter, and CMD counters require delayed expansion. In a .bat file: setlocal enabledelayedexpansion, then set /a count=1, then loop, for /f "delims=" %%f in ('dir /b *.jpg') do ( ren "%%f" "Photo_!count!.jpg" & set /a count+=1 ). The !count! syntax reads the counter as it changes inside the loop, which ordinary %count% would not do. It's fiddlier than PowerShell's equivalent, but it works entirely within CMD.

Always test on a copy first. Like any batch rename, a loop applies to every matching file at once, and CMD has no dry-run preview the way PowerShell's -WhatIf does, so run it against a throwaway folder before your real files.

Saving It as a Reusable .bat Script

The real payoff of CMD renaming is repeatability. Once a loop does what you want, saving it as a .bat file turns it into a one-click tool you can drop into any folder and run again. Keep a small library of these, one for prefixing, one for numbering, one for extension changes, and routine renames become instant. That's CMD's sweet spot: simple, scriptable, always available.

A .bat file is just plain text, so you can reopen it, tweak the prefix or the target extension, and save it again in seconds with no rebuild and nothing to install. It is worth adding a rem line at the top of each script that describes what it does and which folder it expects to run in. That one comment keeps your little rename toolkit readable months later, when you have long forgotten the exact loop syntax but still want to reuse the script.

CMD's Limit: No Regex, and No Reading Files

CMD has two boundaries worth knowing before you start. The first is that it has no regular expressions. ren and for handle wildcards and positional matching, but they can't do find-and-replace on part of a name, reorder a date, or match a complex pattern. The moment you need that, PowerShell is the answer, its -replace operator takes full regex, and everything you can do in CMD you can do more flexibly there.

The second boundary is shared by every scripting approach: CMD works on filenames, never on file contents. It cannot read a scanned invoice and name it by the vendor, because that information is inside the PDF, not in the filename. Naming files by what they contain is content-aware renaming, a different kind of tool that uses OCR to read the page. For pattern and wildcard work, CMD is the right, free choice; for regex, step up to PowerShell; and for content-based naming, see the bulk rename software overview.

When to Move Beyond CMD

CMD is the right tool when the rename is a wildcard swap, a prefix, or a numbered sequence. Reach past it in two cases. If you need pattern matching or find-and-replace, use PowerShell rename multiple files, which adds full regular expressions and a -WhatIf preview. If you'd rather not type commands at all, how to rename multiple files on Windows covers the File Explorer and PowerToys graphical methods. All three sit under the bulk rename software hub.

Frequently Asked Questions

How do I rename multiple files at once in CMD?

Use ren with wildcards for simple cases, such as ren *.jpeg *.jpg, or a for loop to transform each file: for %f in (*.txt) do ren "%f" "new-%f". Inside a .bat file, double the percent sign to %%f.

How do I number files sequentially in CMD?

In a .bat file, enable delayed expansion (setlocal enabledelayedexpansion), set a counter, and increment it inside a for /f loop: ren "%%f" "Photo_!count!.jpg" & set /a count+=1. Test on a copy first, CMD has no dry-run preview.

Can CMD do a find-and-replace on filenames?

No. CMD handles wildcards and positional matching but has no regular expressions, so it can't replace part of a name or reorder text. For that, use PowerShell, whose -replace operator takes full regex.

How do I make a rename repeatable in CMD?

Save the working command or loop in a text file with a .bat extension. You can then drop that .bat into any folder and run it to apply the same rename again, effectively a small reusable tool.

Why does ren fail with a duplicate file name error?

ren will not overwrite a file that already carries the target name, and it cannot move a file into another folder. Both the old and new names must sit in the same directory, and the new name has to be free. Rename or delete the conflicting file first, then run ren again.

Do I need to double the percent sign in a for loop?

Only inside a .bat file. Typed straight at the prompt you use a single percent, for %f in (*.txt) do ren ... , but saved in a script the parser expects %%f, so for %%f in (*.txt) do ren ... . Using the wrong form is the most common reason a copied loop refuses to run.

Can CMD rename files based on what's inside them?

No. CMD only sees filenames and paths, not the contents of a document. Naming a file by what's printed inside it (like an invoice's vendor and date) requires content-aware OCR renaming, which is a different type of tool.