Batch Rename File Extensions with Command Prompt / PowerShell

Print View Mobile View

In this post I will show you how to rename file extensions in Windows from the command line. We’re going to do this using the built-in Command Prompt and Windows PowerShell. No third-party tools are required.

Rename File Extensions Using Command Prompt

  • Rename all file extensions in a folder

To rename all file extension in a folder we can just use the rename command. For example, say you have a folder with 100s of jpeg files, and you want to rename them to .jpg. You can do that with this command:

rename *.jpeg *.jpg

And you’re done. This command works only in the directory you’re in. So if you wanted to rename extensions of files in sub-folders as well, this wouldn’t do. To do that, have a look at the next command.

  • Rename all file extensions in a folder and its sub-folders

To recursively rename extensions in all sub-folders you can use this command:

forfiles /S /M *.jpeg /C "cmd /c rename @file @fname.jpg"

Rename Using Command Prompt

Rename File Extensions Using Windows PowerShell

  • Rename all file extensions in a folder

To rename extensions of all file in a folder, you can use this PowerShell command:

Get-ChildItem *.jpeg | Rename-Item -newname { $_.name -replace '.jpeg','.jpg' }

Just like with the first Command Prompt command, this works only in the directory you are in.

  • Rename all file extensions in a folder and its sub-folders

To rename extensions in the main folder as well as all its sub-folders, you just have to add the -Recurse parameter to the above command. This will give you something likes this:

dir -Recurse *.jpeg | Rename-Item -newname { $_.name -replace '.jpeg','.jpg' }

Rename using Windows PowerShell
This command will scan and rename all .jpeg files to .jpg in the sub-folders. Did you notice I’ve used Dir here? Well, Dir is just an alias for Get-ChildItem. You can use either.