Batch rename multiple files using the Windows 10 command line.
One common task for users on Windows 10 is figuring out how to batch rename multiple files with cmd in Windows 10. Often, the need arises to rename multiple files using batch script instead of manual methods, which can be tedious and time-consuming.
How to rename multiple files with Windows cmd at the same time? One solution is to use third party software like bulk rename utility, or the F2 option in the GUI, but the latter is not as flexible as scripting. However, it is simple and effective to use a cmd request. Here are different command line options to rename a series of several files in batch and in a very fast way. Indeed, these commands make it easy to rename multiple files at once with different names or patterns.
Table of Contents
Before renaming the files
Before diving into the specific methods, it’s essential to understand some basics. For those who are curious about how to create a batch script to rename files in a folder, here are two crucial steps:
- Open the Windows command window
- Go to the working directory with the cd command. Or use the full path of the folder that contains the files to be renamed.
For example, if the files to rename are in the folder C:\Folder\SubFolder then use the command below. The double quotes are used to handle folder names with spaces.
1. Batch rename Windows 10 files with cmd
To rename a large number of files with Windows, simply use the DOS rename command with the * option which allows you to designate all files with a filter. This powerful command can be employed in a batch script rename files sequentially or based on certain patterns. For example, to rename all Word or docx files starting with chapter1* to chapter2*, use this command:
rename chapter1*.docx chapter2*.docx
2. Batch rename or remove the prefix of several files
To rename the prefix of several files, indicate the new prefix or add as many / characters as there are characters to be removed. To illustrate a common use case, we have multiple text files with a prefix to replace by a shorter prefix. The goal is to replace prefix by new
This example cmd script renames the prefix “prefix” to “new”:
rename "prefix_*.txt" "///new_*.txt"
This other command below removes the prefix from all files, however, note that it is not generic and you need to use exactly the right number of backslash in the script. For example to delete the pre_ prefix with 4 letters, use this formula : ////
rename "prefix_*.txt" "///////*.txt" rename "pre_*.txt" "////*.txt"
3. Delete or rename the suffix of multiple files
To rename the suffix of several files, the method is similar to the one used for the prefixes. As before, indicate the prefix and add as many “/” characters as there are letters to delete:
rename "*_suffix.txt" "*///////.txt" rename "*_copy.txt" "*/////.txt"
To rename the suffix with a new string.
rename "*suffix1.txt" "*suffix2.txt"
4. Rename files in batch to remove parenthesis
Sometime you need to rename multiple files with Windows command prompt to remove a specific character. Indeed it is convenient to remove an unwanted part of the filename, like the parenthesis. For example after using the F2 option to rename several files with Windows Explorer. Or after making copies with the Windows copy and paste shortcut for example. Windows adds at the end of the files :
- file Copy.txt
- file Copy (2).txt
- file Copy (3).txt
- file Copy (4).txt
As this command is on multiple lines, it should be saved in a text file and renamed to .bat, like parentheses.bat for example.
cd C:\Folder\SubFolder_1 setlocal enabledelayedexpansion for %%i in (*.txt) do ( set f=%%i set f=!f:^(=! set f=!f:^)=! ren "%%i" "!f!" )
Then execute it with a Right-Click and then “Run as administrator“. Thanks to Tips Box channel for the original solution. The result will be :
- file Copy 2.txt
- file Copy 3.txt
- file Copy 4.txt
5. Rename the extension of several text or PDF files
To rename the file extension only and not the full file name, use this command.
rename *.text *.txt
Often, there’s a need to rename multiple pdf files at once with different names or extensions. To tackle this, use the following command:
rename *.* *.pdf
6. Rename thousands of Excel files quickly
Moreover, the main advantage of renaming files in series is the speed. For example, to rename several files, like tens of thousands of images, use this batch and adapt it. In this scenario, it renames Excel files to remove a part of the name.
rename *_accounting_files_2020.xlsx *_2020_*.xlsx
7. Batch rename several image files
For images like JPG or PNG, it’s similar to other file extensions. It is only the extension filter that changes in the script. For example, how to rename files with the extension .JPG to .JPEG ?
rename *.jpg to *.jpeg
As you can see the rename, or ren, command has a wide variety of usage and it is very powerful compared to manually renaming dozens of files. Check out also how to copy recursively multiple files with a batch. Recursivity is very powerful concept widely used in IT and scripting.
Conclusion on batch rename files in Windows 10
In conclusion, the Windows command prompt provides a powerful and efficient way to rename multiple files with Windows cmd tools without any third-party software. Through the use of various rename command options, you can easily change prefixes, suffixes, remove unwanted characters, and even rename file extensions.
This tutorial has covered several examples that can be adapted to your needs, making it a valuable resource for anyone looking to manage their files more effectively. Remember to always navigate to the appropriate directory before executing any commands, and practice caution when making changes to your files. With these tools at your disposal, you can streamline your file management and save time and effort in the process.