Renaming Files
To rename a file, use the rename command (short form: ren) in the form rename current_name new_name.
This page covers renaming a single file, changing extensions in bulk with wildcards, and adding a prefix to every file with a for loop. The same syntax works in batch files.
The Command to Use
Use the rename command to change a file name. Typing the short form ren gives the same result.
Specify the current name as the first argument and the new name as the second. It also works for folders.
rename does not accept a drive or path in the new name. To move a file to another folder, use move.
Run from Command Prompt
This renames “before.txt” in the current directory to “after.txt”.
Run from a Batch File
@echo off
setlocal
set "FOLDER=%USERPROFILE%\Documents"
rename "%FOLDER%\before.txt" "after.txt"
endlocal
exit /b
If a file with the new name already exists, or the file is open in another application, rename fails with an error such as “A duplicate file name exists, or the file cannot be found.” and nothing is renamed.
Renaming Multiple Files at Once
rename accepts wildcards in both arguments, so you can rename many files at once. A few examples follow.
Renaming with Wildcards
This changes the extension of every .txt file in the “disposable” folder to .html.
The * in the second argument carries over the matched part of each file name from the first argument.

中小企業経営者のためのRPA入門 RPA導入を成功させる方法

60分でわかる! AIエージェント 超 入門

コマンドラインの黒い画面が怖いんです。

知識・才能ゼロでもらく~に月10万円稼ぐ! よくわかるAI副業超入門
Renaming with a for Loop
Adding a fixed string to the start of many file names cannot be expressed with wildcards alone, so use a for loop.
This adds “renamed_” to the start of every file in the current directory. Folders are not affected.
The command above is for typing directly into Command Prompt. In a batch file, write the variable with two percent signs, such as %%f.
In the command above, both "%f" and "renamed_%f" work without double quotes.
However, if a file name contains a space, omitting the quotes causes a syntax error and the rename is not performed.
Since target files may contain spaces, we recommend always using double quotes.
for %f in (*) reads the folder listing while renaming is in progress, so files that were already renamed can be processed again and end up named like “renamed_renamed_…”. To process each file exactly once, fix the list first with dir: for /f "delims=" %f in ('dir /b /a-d') do rename "%f" "renamed_%f".
As an example, assume the following folder structure.
C:\test
│
└─disposable
sample01.txt
sample02.txt
sample03.txt
sample04.txt
Running the command with C:\test\disposable as the current directory prints the following.
Checking the folder shows the files have been renamed.
C:\test
│
└─disposable
renamed_sample01.txt
renamed_sample02.txt
renamed_sample03.txt
renamed_sample04.txt