Tech News Today
  • Hardware
    • Motherboards
    • CPUs
    • Graphic Cards
    • RAM
    • SSDs
    • Computer Cases
    • Monitors
    • Peripherals
    • Power Supply Unit
    • PC Builds
    • Computer Tips
  • Software
  • Operating System
    • Windows
    • Mac
    • Linux
  • Gaming
  • Mobile
  • Console
  • More
    • Internet
    • Networking
    • Security
    • Buyer’s Guide
    • Gadgets
    • Laptops
    • Reviews
    • How To
    • News
Facebook Twitter Instagram
Tech News Today
  • Hardware
    • Motherboards
    • CPUs
    • Graphic Cards
    • RAM
    • SSDs
    • Computer Cases
    • Monitors
    • Peripherals
    • Power Supply Unit
    • PC Builds
    • Computer Tips
  • Software
  • Operating System
    • Windows
    • Mac
    • Linux
  • Gaming
  • Mobile
  • Console
  • More
    • Internet
    • Networking
    • Security
    • Buyer’s Guide
    • Gadgets
    • Laptops
    • Reviews
    • How To
    • News
Tech News Today
Home»Windows»How to Batch Rename Files in Windows (6 Ways)

How to Batch Rename Files in Windows (6 Ways)

Abhishek SilwalBy Abhishek SilwalAugust 23, 2022
Batch Rename Files

Renaming files one by one might not take much time if there are only a few files. However, if you need to rename multiple miles, you definitely want to batch or bulk rename the files.

So we have created this article to help provide you with different methods to rename your files in bulk. They provide different options, so we advise you to go through all of them and pick one according to your preference.

Table of Contents

  • Why Batch Rename Files?
  • How to Batch Rename Files in Windows
    • Using File Explorer’s Rename Feature
    • Using PowerRename Feature of PowerToys
    • Using Command Prompt
    • Using Windows PowerShell
    • Using Third Party Tools

Why Batch Rename Files?

There are many reasons why you may want to batch rename files, such as:

  • Many files available on the internet have generic or indistinguishable filenames.
  • The default filenames of photos or videos captured by cameras use the date and time to create names, which you may want to change.
  • Organizing your files, for instance, renaming music files to listen to them in the order you prefer.
  • Uploading or transferring multiple files on a platform with a different naming convention.

How to Batch Rename Files in Windows

There are a few ways to batch rename files in Windows. You can either use the limited GUI rename ability or use the Command-line Interfaces for more options. There are dedicated naming applications available on the internet, along with Microsoft’s own PowerRename utility.

People usually want to rename files in the following manner:

  • Replacing or removing parts of a file.
  • Changing extensions.
  • Adding a sequence of numbers to the file.
  • Changing case or capitalization.
  • Naming files based on input from a text file.

So, we have explained how you can perform these tasks in detail in the following subsections:

Using File Explorer’s Rename Feature

The first method to batch rename files in Windows is the one most users are familiar with, i.e., using the File Explorer’s rename feature.

However, keep in mind that it provides very limited options on the names you can set. To explain more, all the renamed files will have the same file name along with ascending numbers inside parenthesis.

To rename the files,

  1. Make sure all the files you want to rename are in the necessary order.
  2. Select all the files and right-click on the first item.
  3. Click Rename or Show more options > Rename.
  4. Type the new filename and press Enter.
    rename-file-explorer

Using PowerRename Feature of PowerToys

PowerToys is a Microsoft Developed Tool that you can use to perform varieties of extended functions on your Windows system. One of the utilities included in the PowerToys package is the PowerRename utility.

It helps bulk rename your files while providing advanced options for searching and replacing the name parts.

To use it to batch rename your file,

  1. Download and install PowerToys from Microsoft’s Platform.
  2. Open the File Explorer and navigate to the files you want to rename.
  3. Select all such files and choose PowerRename or Show more options > PowerRename.
  4. Select the options you want and click Apply.
    powerrename

There are many options you can use with this utility, such as:

  • Searching and replacing characters on the filename.
  • Changing the case style of the names.
  • Adding sequential numbers to the end of the names.
  • Adding date and time information in a different format to the names. (Click on the ‘i’ icon next to the Replace with the textbox)
  • By enabling Use regular expressions, you can use specific wildcards on the Search for the textbox (click on the ‘i’ icon next to this box)

Using Command Prompt

You can also use the Command Prompt command ren or rename to batch rename files in Windows. The syntax for the command is, ren [<drive>:][<path>]<filename1> <filename2> where, the parameters in the brackets ([ ]) are optional.

There are more than one ways to rename files using this command. Moreover, you can also use such commands as a batch script for future uses.

First, open the Command Prompt and change your directory to the folder whose files you wish to rename. To do so,

  1. Open Run and enter cmd to open Command Prompt.
  2. Enter cd /d <full path of the folder> while replacing the full path.

You can also open the folder in the File explorer and enter cmd on its address bar to open the Command Prompt directly at the working path.

Then, apply the steps below depending on how you want to rename the files.

Rename Extension

  1. To rename an extension, you can use the following command:
    ren *.<ext 1> *.<ext 2>
    You can replace <ext 1> and <ext 2> as per your need. For example, ren *.png *.jpg
    rename-extension
  2. Similarly, to remove an extension. the command is ren *.<ext> *
  3. And, to add an extension, use ren *. *.<ext>
Note: Please bear in mind that the above command only changes the name of the extension but not the encoding of the file.

Removing the Initial Characters

Many users think it’s a bug, however, you can remove the initial characters from the filenames in the following manner:

  • The command is ren “*.*” “<slashes>*.*”
    For example, to remove the first three characters, the command is ren “*.*” “///*.*”
  • Keep in mind that both the filenames must be enclosed in quotes.
  • However, it doesn’t remove the ‘.’ icon and the truncating process stops after the point is reached no matter how many forward slashes you use. For example, ren “*.*” “///////*.*” renames abc.b.c.txt to .b.c.txt

Removing Parts of the Filename

It is possible to remove parts of a filename if the parts are separated by delimiters, such as space, tab, or a non-alphanumeric symbol. It helps you rename some of the portions separated by the delimiters as the new name.

In the filename abc_def xyz.txt, the underscore ‘_’, the space ‘ ’ and the point ‘.’ are the delimiters.

However, you can’t use the parts of the filename that are not separated by such delimiters as the new filename.

Let’s take an example of removing the parts on the filenames where the delimiter is an underscore “_”.

If there’s only one underscore, you can remove everything before the underscore by using the command below:

  • for /f "tokens=1,2,* delims=_" %F in ('dir /b "*_*"') do ren "%F_%G" "%G"rename-part-of-filename

where,

  • delims specifies the delimiter for this process, in this case, the underscore “_”.
  • tokens specify which parts of the filename to assign new variables.
  • In this case, where tokens=1,2,* and the starting variable is %F, the command assigns the two parts of the filename to variables %F and %G respectively.
  • You can use other variables in place of F as well.

If there are multiple underscores, such as a_b_c.txt, to remove everything except the parts after the last underscore,

The command is,

  • for /f "tokens=1,2,3,* delims=_" %F in ('dir /b "*_*_*"') do ren "%F_%G_%H" "%H"rename-part-of-filename-two-delims

Here, tokens 1, 2, and 3 take the three portions of the filename separated by the two _ and set them to %F, %G, and %H in order. Then, it renames %F_%G_%H to %H only.

Similarly, you can rename it to other parts of the filenames, such as %F or %G (second part) by replacing the last part of the command. However, this removes the extension as well.

You can also specify multiple delimiters. For example, if we want to batch rename files in the form of a_b-c.txt to a.txt, we can enter

  • for /f "tokens=1,2,3,4,* delims=_-." %F in ('dir /b "*_*-*.*"') do ren "%F_%G-%H.%I" "%F.%I"

where %F, %G, %H, %I take a,b,c and txt respectively.

However, you should keep in mind that you can’t use the same name for multiple files. So if this method results in renaming more than one file to the same name, the command loop stops immediately.

Also, if you want to use the for-loop in a batch script, you need to replace the ‘%’ sign with two % signs. For instance, you need to replace the variable %F with %%F. For more information on using for-loop in Command Prompt, refer to the for Microsoft Documentation.

Appending Characters at Start or End

If you think that using the ‘*’ or the ‘?’ wildcards allows appending characters to the name, you would be incorrect. For instance, using ren *.mp3 ab*.mp3 does not rename file.mp3 to abfile.mo3, but to able.mp3. So you need a different method.

This method uses a similar command syntax as the above method. Usually, you can use it to append some characters at the start or the end of the filename. However, if there are other delimiters in the filename, you can also add characters to the start or the end of these delimiters.

Let’s use a simple example,

  • To rename a.txt to file a name.txt, the command is
    for /f "tokens=1,2,* delims=." %F in ('dir /b "*.*"') do ren "%F.%G" "file %F name.%G"
    rename-append-characters
  • You can similarly add characters at only the start or only the end.

Together with the above method (using part of a filename), appending characters to the name offers high customization for batch renaming files in Windows.

Appending Sequential Numbers

The above method only allows adding the same sets of characters to the filenames. If you want to append sequential numbers to the files, you need to use a batch file. Follow the steps below to do so,

  1. Open Run and enter notepad to open Notepad.
  2. Enter the script given below while replacing the components as we have directed.
  3. Press Ctrl + Shift + S to Save As the file with different extension.
  4. Set the Save as type to All files and File name to any name you want with a .bat extension, e.g, rename_sequence.bat
    save-as-bat
  5. Move the batch file to the location of the files you wish to rename.
  6. Run the script by double-clicking on it.
setlocal enabledelayedexpansion
set /a Number=1

for /r %%F in (*.txt) do (
    ren "%%F" "%%~nF !Number!.txt"
    set /a Number+=1
)
endlocal

Here,

  • You need to replace .txt with the extension of the files you wish to rename. Don’t use the wildcard * for the extension as you need to place the batch file in the same folder. So, if you use the wildcard, the command also includes the batch file while renaming the files.
  • The Number variable works as a counter starting from 1 that you append to the file. You can replace it with the starting number of your choice.
  • The %%~nF !Number! adds a space and the sequential number to the files. You can place !Number! anywhere in the new filename as your preference.
  • %%~nF expands %%F to the filename without the path and extension. If you just use, %%F, it will include the extension as well as the path of the files resulting in an error.
  • The command setlocal enabledelayedexpansion allows using multiple commands on the for-loop. If you don’t enter it, the value of Number won’t change in the successive executions.

Together with the previous methods, you can take out some parts of the filename and add numbers to it for easier recognition and organization. For example, 11001.picfile.2022198.1211.png and 11001.picfile.2022198.1215.png to picfile 1.png and picfile 2.png

Moreover, if you want to use numbers with 0 at the start like 01, 02, 03, etc., you need to add conditions on the script, such as:

setlocal enabledelayedexpansion
set /a Number=1

for /r %%F in (*.txt) do (
    if !Number! lss 10 (
        ren "%%F" "%%~nF 0!Number!.txt"
    ) else (
        ren "%%F" "%%~nF !Number!.txt"
    )
    set /a Number+=1
)
endlocal

Similarly, for 001, 002, 003, etc., number format, use the else if branch to append 00 if less than 10 and append 0 if less than 100.

Taking Input From Text File

It is also possible to batch rename files by taking inputs from a text file. You also need to use a batch script for this method.

  1. First, create a text file with the new filenames in each line. In our example, the file is filename.txt.
  2. Make sure the files you wish to rename are in the correct order. Arbitrarily rename them if they aren’t.
  3. Use the steps from the above method to make the .bat file with the script below (after making changes as necessary) and run it.
    rename-from-text-file
setlocal EnableDelayedExpansion

< filename.txt (
    for %%F in (*.mp3) do (
        set /P name=
        ren "%%F" "!name!.mp3"
    )
)
endlocal
  • Here, the filename.txt includes the name for all the files and you can change the extension .mp3 to the one you need.
  • Also, if you are renaming .txt files, you need to add a condition to avoid renaming the filename.txt file. The complete script is,
setlocal EnableDelayedExpansion

< filename.txt (
    for %%F in (*.txt) do (
        if NOT %%F==filename.txt (
            set /P name=
            ren "%%F" "!name!.txt"
        )
    )
)
endlocal

Convert to Uppercase or Lowercase

It is very easy to convert all letters to lowercase. The command is:

  • for /f "Tokens=*" %f in ('dir /l /b /a-d') do (ren "%f" "%f"),

where, the /l flag gives the directory’s files in lowercase, causing the ren command to use lowercase for all files. Windows Command line is not case-sensitive so it thinks both uppercase and lowercase are the same characters, making it possible to use this replacement.

However, the dir command does not have any flags for providing the filenames in uppercase. So you need to use the following batch script using the steps in the Adding Sequential Numbers method:

setlocal enableDelayedExpansion

for %%F in (*.mp3) do (
   set "name=%%~nF"
   for %%I in (A B C D E F G H I J K L M N O P Q R S T U V W X Y Z) do (
      set "name=!name:%%I=%%I!"
   )
    ren "%%f" "!name!%%~xF" >nul 2>&
)
endlocal

You should change .mp3 to the extension of your files.

This script doesn’t change the case of the extensions. However, if you also want to change the extensions to uppercase, replace:

  • name=%%~nF with name=%%F
  • !name!%%~xF with !name!

Wildcard Behavior in Rename Command

As we mentioned earlier, the * and ? wildcards do not behave as you would normally think if you use them on both the source and the destination filenames

A superuser forum user dbenham has explained this behavior in detail in the forum. We recommend you check the forum page to get the complete information.

Using Windows PowerShell

Windows PowerShell is a very powerful Command-line Interface that provides more options and functionalities.

Similar to Command Prompt, first, type powershell on the address bar of the folder whose files you need to rename and press Enter. Or you can open Windows PowerShell in any other way and change to the directory.

After that, apply the methods below depending on how you want to batch rename the files.

Rename Extension

  • The Windows PowerShell command to batch rename extension is:
    Get-ChildItem *.<ext 1> | Rename-Item -NewName { $_.Name -replace ".<ext 1>",".<ext 2>" }
  • Similarly, you can put just "." in place of ".<ext 2>" to remove the extension.
  • To add an extension, use the command Get-ChildItem *.<ext> | Rename-Item -NewName { $_.Name + ".<ext>" }

You can use the End-of-file (eof) character $ after the old extension to only allow the last instance of the extension to change. For example,

  • Get-ChildItem *.jpg | Rename-Item -NewName { $_.Name -replace ".jpg",".png" } changes a.jpg.jpg to a.png.png
  • Get-ChildItem *.jpg | Rename-Item -NewName { $_.Name -replace ".jpg$",".png" } changes a.jpg.jpg to a.jpg.png

There’s also another way to rename the extension, which uses the System.IO class. The syntax for this method is:

  • Get-ChildItem *.<old ext> | Rename-Item -NewName { [io.path]::ChangeExtension($_.Name, ".<new ext>")powershell-rename-extension

You can also use the -Recurse flag for Get-ChildItem to allow the command to work on all the files in the working directory’s subfolders.

Removing or Replacing Specific Characters

Unlike Command Prompt, in PowerShell, you normally use the character replacing operator -replace to rename files. So, you can directly replace particular sets of adjacent characters with a new one or set the replacement to an empty value to remove the characters.

For example, to rename file 01.mp3 to Music01.mp3, you can use the command:

  • Get-ChildItem *.mp3 | Rename-Item -NewName { $_.Name -replace "file ","Music" }

Removing or Replacing Characters at Any Position

To replace characters at any position in Windows PowerShell, you can use the command:

  • Get-ChildItem *.<ext> | Rename-Item -NewName { $_.Name.SubString(<StartIndex>,<Length of Characters>) }

while replacing the following portions:

  • <StartIndex> with the position you want to start for the new filename.
  • <Length of Characters> with the length you want for the new filename.

For instance, Get-ChildItem *.mp3 | Rename-Item -NewName { $_.Name.substring(2,$_.Name.length-5) } renames abcdefgh.mp3 to cdefgh

A filename’s first position is zero, so the character of the new name starts from the third character. And the length is determined from the final position, which is 11 including the extension. So you are taking 11-5=6 characters to form the new name.

You need to take note of the extension length in this method. You can directly add the extension in the command to avoid having to change it again. To do so, the command for the example would be:

  • Get-ChildItem *.mp3 | Rename-Item -NewName { $_.Name.substring(2,$_.Name.length-5) + “.mp3” }
    replace name powershell with extension.jpg

Appending Characters at the Start or the End

Appending the characters is more convenient with PowerShell than Command Prompt, specifically because you can use the ‘+’ operator to add the names and $_.Name value to get the original filename.

  • The command is something like the following:
    Get-ChildItem *.<ext> | Rename-Item -NewName { “Starting Appending Part” + $_.Name + “Ending Appending Part" }
  • However, to append on the end part of the name excluding the extension, you need to use the $_.BaseName and $_.Extension variables in the following manner:
    Get-ChildItem *.<ext> | Rename-Item -NewName { “Starting Appending Part” + $_.BaseName + “Ending Appending Part" + $_.Extension }
    append-characters-filename-powershell

Appending Sequential Numbers

Similar to the above methods, it is much easier to append sequential numbers on PowerShell. Here’s how you can do so:

  1. On PowerShell, type $i = 1 and press Enter to set the counter value. You can change it to the number you want the sequence to start at.
  2. Then, enter Get-ChildItem *.<ext> | Foreach-Object {Rename-Item $_ -NewName ($_.BaseName + “ {0:D3}” + $_.Extension ) }
    powershell-sequential-number

You can replace D3 with how many digits you want. For instance, {0:D3} appends the three-digit numbers: 001, 002, and so on.

You can also place the number anywhere on the name.

Taking Input From Text File

Taking input from a text file is slightly more complex, so the best way to do so using this Command Line is by creating a PowerShell script. Here’s how you can do so:

  1. Open Run and enter notepad.
  2. Copy and Paste the script below while changing the relevant components as we have directed.
  3. Press Ctrl + Shift + S.
  4. Set the Save as type to All files and File name to any name you want with a .ps1 extension, e.g, rename_from_text.ps1
  5. Move the batch file to the location of the files you wish to rename.
  6. Create another text file where each lines contains the new name for the files in order. Save it as a text file (.txt) on the same location. In the example, we have used filename.txt
  7. Run the PowerShell script by right-clicking on it and selecting Run with PowerShell.
$FilesToChange = Get-ChildItem *.mp3
$NameFile = Get-Content filename.txt
if($FilesToChange.FullName.Count -eq $NameFile.Count)
{
    for($i=0; $i -lt $NameFile.Count; $i++)
    {
        Rename-Item -Path $FilesToChange.FullName[$i] -NewName ($NameFile[$i]+".mp3")
    }
}
Note: If you get the Cannot Be Loaded Because Running Scripts Is Disabled On This System error message, open PowerShell as admin and enter the command:
Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy RemoteSigned

You need to change .mp3 to the extension of your files and filename.txt to the text file with the list.

If you want to convert the names of text files, you need to add a condition to the script. The complete script is:

$FilesToChange = Get-ChildItem *.mp3
$NameFile = Get-Content filename.txt
$j=0
if($FilesToChange.FullName.Count -eq $NameFile.Count)
{
    for($i=0; $i -lt $NameFile.Count; $i++)
    {
        if ($FilesToChange.BaseName[$i]+$FilesToChange.Extension[$i] -eq "a.mp3")  
        {
            continue
        }
        Rename-Item -Path $FilesToChange.FullName[$i] -NewName ($NameFile[$j]+".mp3")
        $j++
    }
}

Convert to Uppercase or Lowercase

Here are the commands you can use to change the case of your files:

  • To Change All to Lowercase
    Get-ChildItem | Rename-Item -NewName {$_.BaseName.ToLower() + $_.Extension.ToLower()}
    rename-to-lowercase-powershell
  • To Change All to Uppercase
    Get-ChildItem | Rename-Item -NewName {$_.BaseName.ToUpper() + $_.Extension.ToUpper()}
  • To Change The Name Without Extension to Uppercase
    Get-ChildItem | Rename-Item -NewName {$_.BaseName.ToUpper() + $_.Extension.ToLower()}

Using Third Party Tools

Many third-party tools like Bulk Rename Utility, File Renamer Basic, Advanced Renamer, etc., are available on the internet, which you can use to batch rename your files. These apps provide more customization and features compared to the PowerRename Utility.

You can download and use any one of them by following the tutorials from their official website.

how-to
Abhishek Silwal
  • LinkedIn

Abhishek Silwal is an Electronics Engineer and a technical writer at TechNewsToday. He specializes in troubleshooting a wide range of computer-related issues. His educational background in Electronics Engineering has given him a solid foundation in understanding of computers. He is also proficient in several programming languages and has worked on various robotics projects. Even in his early days, he used to tinker with various computer components, both hardware, and software, to satiate his curiosity. This experience has given him a breadth of experience that goes beyond his educational qualification. Abhishek has been writing articles on dealing with varieties of technical issues and performing specific tasks, especially on a Windows machine. He strives to create comprehensive guides on fixing many system and hardware issues and help others solve their problems. You can contact him at abhisheksilwal@technewtoday.com

Related Posts

amd-software-not-opening

How to Fix AMD Software Not Opening

March 3, 2023
how to create a folder

7 Ways to Create a Folder on Windows

March 3, 2023
turn off automatic updates windows

How to Turn Off Automatic Updates on Windows

March 2, 2023
Memory-Compression

What is Memory Compression in Windows? Should You Enable or Disable It

March 1, 2023
dism-vs-sfc-vs-chdsk

DISM, SFC, CHKDSK: What’s the Difference

February 28, 2023
how-to-open-exe-file

4 Ways to Open EXE File

March 2, 2023
Add A Comment

Leave A Reply Cancel Reply

Latest Posts
Memory-Compression

What is Memory Compression in Windows? Should You Enable or Disable It

March 1, 2023
dism-vs-sfc-vs-chdsk

DISM, SFC, CHKDSK: What’s the Difference

February 28, 2023
bios-settings-for-gaming

Best BIOS Settings for Gaming

February 16, 2023
You may also like
how-to-clean-hp-printer-rollers

How to Clean HP Printer Rollers

March 3, 2023
keyboard input lag

9 Ways to Fix Keyboard Input Lag

March 3, 2023
keyboard key is stuck

How to Fix a Stuck Key on a Keyboard

March 3, 2023
Recommended
Cookie Clicker Garden Guide

Cookie Clicker Garden Guide to Unlocking Every Seed

September 26, 2021
monitor no signal

Computer Turns On But Monitor Says No Signal (9 Ways To Fix)

November 10, 2022
Facebook Twitter Pinterest
  • Home
  • About Us
  • Our Team
  • Editorial Guidelines
  • Privacy Policy
  • Affiliate Disclosure
© 2023 TechNewsToday, editor@technewstoday.com | Tech Central Pvt. Ltd.

Type above and press Enter to search. Press Esc to cancel.