Renaming files in Windows using the Command Prompt (CMD) is straightforward. Below is a guide to various methods:
1. Rename a Single File
To rename a single file, use the ren
or rename
command.
Syntax:
ren [current_filename] [new_filename]
Example:
If you want to rename file1.txt
to file2.txt
:
ren file1.txt file2.txt
2. Rename Files in a Different Directory
If the file is located in a different folder, include the file’s path.
Example:
To rename a file located in C:\Documents
:
ren "C:\Documents\file1.txt" "file2.txt"
3. Rename Multiple Files with Wildcards
You can rename multiple files using wildcards like *
or ?
.
*
matches multiple characters.?
matches a single character.
Example 1: Rename all .txt
files to .bak
files:
ren *.txt *.bak
Example 2: Rename files with specific patterns:
To rename file1.txt
, file2.txt
, etc., to document1.txt
, document2.txt
:
ren file*.txt document*.txt
4. Rename Files by Changing Extensions
You can also use the ren
command to change file extensions.
Example:
Rename all .jpg
files to .png
:
ren *.jpg *.png
5. Rename Files Using a Loop (Advanced)
To rename files systematically, use a loop in a batch file.
Example: Add a prefix to all .txt
files:
for %f in (*.txt) do ren "%f" "new_%f"
Key Notes:
- Always enclose file names with spaces in double quotes (
"
). - The
ren
command cannot move files to a different directory—it only renames them. - Be cautious when using wildcards to avoid unintentional renaming.
Conclusion
The ren
command is a powerful and simple way to rename files in CMD, whether you’re working with a single file or multiple files. For more advanced renaming tasks, you can incorporate loops or scripts.