Trending October 2023 # How To Batch Rename Files In Windows (6 Ways) # Suggested November 2023 # Top 17 Popular |

Trending October 2023 # How To Batch Rename Files In Windows (6 Ways) # Suggested November 2023 # Top 17 Popular

You are reading the article How To Batch Rename Files In Windows (6 Ways) updated in October 2023 on the website We hope that the information we have shared is helpful to you. If you find the content interesting and meaningful, please share it with your friends and continue to follow and support us for the latest updates. Suggested November 2023 How To Batch Rename Files In Windows (6 Ways)

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.

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

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:

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,

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.

To use it to batch rename your file,

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

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,

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

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:

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 chúng tôi 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"


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"

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,

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,

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


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.2023198.1211.png and 11001.picfile.2023198.1215.png to picfile chúng tôi 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.

setlocal EnableDelayedExpansion < chúng tôi ( 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 < chúng tôi ( 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!" ) ) 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.

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

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,

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

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:

Removing or Replacing Characters at Any Position

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

while replacing the following portions:

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:

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.

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:

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:

$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") } }

Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy RemoteSigned

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:

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:

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.

You're reading How To Batch Rename Files In Windows (6 Ways)

Update the detailed information about How To Batch Rename Files In Windows (6 Ways) on the website. We hope the article's content will meet your needs, and we will regularly update the information to provide you with the fastest and most accurate information. Have a great day!