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:
- Open a new text file and add: @echo off
- Add the loop: for %%f in (*.txt) do ren "%%f" "archived_%%f"
- Save it with a .bat extension, for example rename-files.bat.
- 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.