Windows OS

How to Rename Batch Files in Windows

There can be a situation when you want to rename a bunch of files. Doing such operations one by one can consume a lot of time and become a nightmare for all of us. However, Windows offers different optimized solutions to rename batch files, using which you can rename hundreds and thousands of files at once.

In this blog, we will provide different methods to rename batch files in Windows.

How to Rename Batch Files in Windows?

Renaming batch files is not as difficult as you think. On your Windows system, you can rename batch files:

    • Using File Explorer
    • Using PowerShell
    • Using CMD

Let’s explore each of the mentioned methods one by one

How to Rename Batch Files in Windows Using File Explorer?

The first and the easiest way to rename batch files in Windows is using File Explorer. In order to change the name of batch files, move to the folder where files are placed and select all of them with the “CTRL+A” shortcut key, then press the “F2” key:


Type the new name and press the “Enter” key to rename the batch files:


As you can see, the batch files have been successfully renamed:


Want to try a command-line method? Check out the next section!

How to Rename Batch Files in Windows Using PowerShell?

As you may know, PowerShell is a more powerful tool and has its own features when we talk about the Command Line Interface tools. We will use Powershell to rename batch files here.

Example 1: Changing File Name of Batch Files

In order to rename batch files in PowerShell, you need to navigate to the folder where the files are located, click on “File” from the menu bar, and hit the “Open Windows PowerShell as administrator” option. This operation will launch PowerShell, and the opened directory will be its current working directory:


Then, execute the “Rename-Item” command and specify the new file name with the “-NewName” option:

> dir | %{$x=0} {Rename-Item $_ -NewName "Aug2022$x.jpg"; $x++ }

 

The command above will take the files collectively, and it will pass those files to the Rename-item command to rename all the files to “Aug2022”. A number will be allocated recursively using the “$x” variable so that each file name should be unique:


As you can see in the above image, all files have been successfully renamed, and a unique number is added at the end of it.

Example 2: Changing File Extension of Batch Files

You can also change the extension of the multiple files in the directory at once by using the command below:

> Get-ChildItem *.jpg | Rename-Item -NewName { $_.Name -replace '.jpg','.png' }

 
The above-given command will fetch all files with the “.jpg” extension using the “Get-ChildItem” command and pass the output to the “Rename-Item” command with the help of the pipeline operator “|”. After that, the Rename-Item command will change their extension to “.png”:


 

How to Rename Batch Files in Windows Using CMD?

Another way of renaming the batch files is using CMD. To do so, firstly, open Command Prompt with administrator privileges. Then, execute the “cd” command to move to the folder where the batch files are present:

> cd C:\Users\Farhan\Documents\Batch Rename Files

 

Next, write out the “ren” command to rename the batch file and specify the desired format in it:

> ren *.jpg ?????????Sep.jpg

 
Here, “*.jpg” will select all the files with the .jpg extension, and then “?????????Sep.jpg” is the new file name format.

Note: You can enter as many question marks as “?” to make space for more characters as you want. If you want to add a name to the start and make space for other characters at the end, then you need to add question marks at the end.


Output


If you want to change the extension of the batch files collectively, then add the current file extension and the desired file extension with the “*” option in the “ren” command:

> ren *.jpg *.png

 

Output


We have provided the methods related to renaming batch files in Windows.

Conclusion

To rename batch files in Windows, you can use Windows Explorer, PowerShell, or Command Prompt. In Windows Explorer, move to the required folder, press “CTRL+A” and then “F2”, and rename files. Whereas, in PowerShell, the “Rename-Item” and in Command Prompt “ren” commands can be utilized for the same purpose. This blog offered various methods related to renaming batch files.

About the author

Sharqa Hameed

I am a Linux enthusiast, I love to read Every Linux blog on the internet. I hold masters degree in computer science and am passionate about learning and teaching.