Using Windows Powershell
Windows Powershell is far more powerful than the regular command prompt and is also easy to use. To batch rename files using Powershell, we need to use two commands, i.e. DIR and Rename-Item. Now to batch rename without changing their extensions, press the WIN button, type “powershell” and press enter button to open Powershell.
Once the Windows Powershell is opened, navigate to your desired directory using CD command. As for me, I’m navigating to D:\mte\ as this is where my files are located.
Once you are in the location, use the below command. While using the command, don’t forget to change “TestName” to your desired file name.
dir | %{$x=0} {Rename-Item $_ -NewName "TestName$x.html"; $x++ }
What the above command does is that it will take all the files in the directory using the DIR command and pass to the “Rename-Item
” command which renames all the files to “TestName*.” Here * denotes numbers, and those numbers are allocated recursively using “$x.”
Now if you want to change the file extensions of all the files in a directory, use the below command.
Get-ChildItem *.html | Rename-Item -NewName { $_.Name -replace '\.html','.txt' }
What the above command does is take all the files with .html extension in a directory and change them to .txt.
To know more about Rename-Item command, read the Microsoft documentation for more definitions and examples.