The following article will teach how to rename multiple files in a folder with the bulk method using Command Line (CMD). Besides the CMD, we will show how you can do it using Powershell and VBS Script. Together with them, we will play using some tricks like how to trim multiple names or add a prefix to file names. Just in case if you want to do this for a single file check our previous article – “script rename file using Command Line”.
Bulk File Rename on Windows
Use Windows Explorer to rename files
Before we move to the commands ant batch, let’s see how we can rename multiple files at once in bulk using file explore.
You can simply use Windows Explorer to rename files If you don’t have a fancy renaming task at hand, or don’t want to install anything.
- Copy all the files which you want to rename, in a single folder.
- Highlight each file which you want to rename. Press Ctrl+A to highlight them all, if not, then press and hold Ctrl and click on each file you want to highlight.
- Once all the files are highlighted, right-click on the first file and click on “Rename” (press F2 to rename the file without making more actions).
Note! Arrange them properly if you want to provide any specific order. Do this task before renaming. The renaming process will start from the first selected file and end on the last with proper numbering sequence.
- Just enter the name which you would like to give and press enter. All the files will be given the same name with a numbering sequel in the end. It’s a pity that Windows is adding spaces, and ( ) characters in names, instead of having a simple _number option. Below we will teach how you can remove the space and other characters that you don’t want in the naming.
How to batch rename multiple files in bulk using CMD
- Open Start.
- Search for Command Prompt and click the result to open the app.
- Type the below command to navigate to the folder where are located the files you want to rename and press Enter:
cd c:\TestPath
- Type the following command to rename multiple files in bulk and press Enter:
rename *.FILE-EXTENSION ???-FILE-NAME.*
In the command, the wildcard ”*” tells the rename command to rename everything with a “.txt” extension. The “?” is also a wildcard, but it represents a character of the original file name.
This command example renames all “.txt” files in the target folder leaving the first three letters (which works as a unique identifier to avoid duplication) and appends “-Test1” to the name:
rename *.txt ???-Test1.*
How to create a simple batch script to rename all files in a folder
If you are going to automate the above activities or to execute over the network you will need to create a batch file. For example, you need to rename all files in a folder located on all computers of the network:
- Open a notepad file
- Copy the below command
@echo off rename “c:\*.txt” “???-Test1.*”
- Save as rename.bat
- Execute the file and all the changes will be done
Note! On this file, you can change the “rename “c:\*.txt” “???-Test1.*” command with the command you want, based on the task you want to archive described in this article.
You can use the batch files for many other simple actions like to delete files in bulk or to delete folders.
How to add a prefix to file names in batch
If you want to add any prefix to file names, it can be done as in the below example. Here we try to add ‘Work’ to every txt file in the current folder and subfolders.
forfiles /S /M *.txt /C "cmd /c rename @file Work@file"
Similarly, we can add a number to a file name.
forfiles /S /M *.txt /C "cmd /c rename @file 112@file"
How to Handling names with white spaces
If the new name you want to assign to the files has white space within it, it can be done by adding double quotes around the file name. So that forfiles does not misinterpret these double-quotes, you need to escape them with ‘\’
For example, to add ” – pic.txt” to each of the jpg files, the command would be as below.
forfiles /M *.txt /C "cmd /c rename @file \"@fname - pic.txt\""
How to create vbs script to rename multiple files in bulk
Consider a case like in the example image above where you have a folder of many images each named Copy of and then a word or two, like Copy of Black Tea.jpg.
Instead of manually renaming each file to delete “Copy of” or to change those words to something else, you could run a vbs script to do all the renaming for you. To create it follow the steps:
- Open a notepad file
- Copy the below command
Set objFso = CreateObject(“Scripting.FileSystemObject”) Set Folder = objFSO.GetFolder(“Path”) For Each File In Folder.Files sNewFile = File.Name sNewFile = Replace(sNewFile,”ORIGINAL”,”REPLACEMENT”) if (sNewFile<>File.Name) then File.Move(File.ParentFolder+”\”+sNewFile) end if Next
- Edit the file rename script to make it apply to your unique situation.
You need to change the text called “Path” to the folder name where your soon-to-be-renamed files are located. In our example c:\Test\
To make the script always apply to the folder it’s currently located in, just change the path to .\.
Also, change ORIGINAL to the characters you want to replace, and delete REPLACEMENT so that you can enter the text that should replace the original characters.
Note: Make sure you keep the quotes in every instance you see them. They need to remain in the folder path and the replace section.
- Save as rename.vbs
- Execute the VBS file to apply the script.
How to Trim Multiple Names
Here is how to trim multiple names simultaneously if you want to make the file names shorter.
For instance, you may have .txt files that you need to trim with names that have already been customized. Inside the target directory, you can add the “ren*.* ?????.*” function. This function will trim the original photos to the number of characters designated by the question marks.
This example will turn a file named “test1_test.txt” into “test1.txt” Of course, if the file name is six characters or less in length, it will remain the same. This is useful where short file names are a better option than long ones.
To make long file names shorter with Command Prompt, use these steps:
- Open Start.
- Search for Command Prompt and click the top result to open the app.
- Type the following command example to navigate to the folder with the files you want to rename and press Enter:
cd c:\TestPath
- Type the following command to make file names shorter and press Enter:
ren *.* CHARACTER-COUNT.*
In the command, the wildcard “*” matches all the file names and extensions in the folder, and the wildcard “?” indicates how many characters to use for the new file name.
This example trims the file names longer than five characters:
ren *.* ?????.*
If the file name is less than five characters, then the name will not change. (If you want to make the file name longer, add extra question marks.)
Once you complete these steps, you’ll end up with shorter file names depending on the question marks (?) you specified in the command.
How to Modify Multiple Names
If you want to rename a specific part of multiple filenames with similar names, here’s how to do it. For example to rename multiple filenames that all start with “Testing_2020” so that they start with “Test_20”
- Open Start.
- Search for Command Prompt and click the top result to open the app.
- Type the following command example to navigate to the folder with the files you want to rename and press Enter:
cd c:\TestPath
- Type the following command to make file names shorter and press Enter:
ren Testing_2020*.* Test_20*.*
This is a handy command for shortening file names.
How to Change Files with Specific Extensions
Now suppose that you have multiple file types within a folder and you want to rename only the ones with the .txt extension. This is very easy on command Prompt. Let us say that you want to rename all files titled “Testing_2020” to “Test_20,” but only those with the .txt extension. Then, type:
ren Testing_2020*.txt Test_20*.txt.
This command will rename all said filenames, like the one above, but it will only do so for .txt files.
How to Change Extensions of multiply files in bulk
Sometimes, you may want to change file extensions for multiple files. You could do this by using the above-mentioned function that allows you to change name parts, but there is an easier way to go about things here.
Once in the desired directory, type in “ren *.txt *.xml” to change all .txt files to .xml files. We have described this better in the following article here.
Powershell rename multiple files at once
- Open Start.
- Search for PowerShell and click the top result to open the app.
- Type the following command to rename a single file and press Enter:
Dir | Rename-Item –NewName { $_.name –replace “ “,”_” }
- The command replaces blank spaces with underscores (_).
This feature offers the most options, but using this method can by time-consuming, and complicated for beginners, which is why we assume that most users will skip this solution.
There you go, PowerShell is the most powerful tool for renaming multiple files in Windows 10. You can experiment with various options and commands, in case you have some free time, and want to learn more about this tool.
Other PowerShell commands:
To replace open bracket:
dir | rename-item -NewName {$_.name -replace [Regex]::Escape("("),""}
To replace close bracket:
dir | rename-item -NewName {$_.name -replace [Regex]::Escape(")"),""}
Conclusion:
So those are the trick to save your daily time and to rename multiple files in folder with the bulk methods. Using CMD, Powershell, or VBS Script. Let’s hope that you find and customize your needs.