Rename file extensions in bulk, including files in subfolders

by admin on July 3, 2012

This post talks about how to rename file extensions in bulk using simple commands. No 3rd party tools are required. At the end of the post, you can find a download link for the batch file script.

Change file extensions in bulk:

We can change the extension of files in the bulk using rename command. For example, you have set of files with extension .log and you want to rename them to .txt.  You can do this with the below command

rename  *.log   *.txt

The drawback with this command is, we can’t use it to rename file extensions recursively in the sub folders. Next, we’ll look at a solution which allows us to do so.

Recursively rename file extensions

If you want to rename files from one extension to another, recursively in all sub folders, then you can use the below command.

forfiles /S /M *.ext1 /C "cmd /c rename @file @fname.ext2"

For example, if you want to rename all xml files to txt files, the command would be as below

forfiles /S /M *.xml /C "cmd /c rename @file @fname.txt"

Remove file extensions

The below command would remove extension for the specified file types.

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

If you want a batch file script, it can be downloaded from the below link:
Batch file script for renaming file extensions in bulk

Add prefix to file names

If you want to add any prefix to file names, it can be done as in the below example. Here we try to add ‘photo’ to every jpg file in the current folder and subfolders.

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

Similarly, we can add a number to a file name.

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

{ 9 comments… read them below or add one }

DPS Chawla February 24, 2014 at 5:17 pm

Great Thanks REgards


atul June 17, 2014 at 11:35 am

thanks for suggestion


devilJake June 18, 2014 at 4:08 pm

I want only the extensions of files starting with certain type of names to be renamed, within the folder as well as subfolders.
How can I do it?
For example:
rename all files starting with the name “*-common.xml” to “*-common.xml.txt”

The other .xml files have to be left intact.


devilJake June 18, 2014 at 5:08 pm

Figured it by out myself.

forfiles /S /M *-common.xml /C “cmd ren *-common.xml *-common.xml.txt”


Cathryne July 10, 2014 at 3:02 pm

Thanks for these hints :-) Is it also possible to include a space in the prefix? I tried the following:

forfiles /S /M *.jpg /C “cmd /c rename @file “photo location – “@file”
=> The syntax of the command is incorrect

forfiles /S /M *.jpg /C “cmd /c rename @file ‘photo location – ‘@file”
=> ERROR: Invalid argument/option…


Volker September 25, 2014 at 9:13 am

I have here some files with ending like this
e.g. file_a(1).txt
I tried this forfiles /S /M *.ext1 /C “cmd /c rename @file @fname.ext2″ for renaming them to .txt
e.g. file_a.txt

Can you help me?


Will October 23, 2014 at 5:06 pm

The “Add prefix to file names” code is faulty. When I ran it, it keeps adding the prefix to all of the files in the folder over and over again until I kill it.


admin October 24, 2014 at 12:02 am

It worked fine for me. Can you tell me how many files you have in the folder that you were intending to add the prefix?

Masim October 29, 2014 at 6:57 am

I just tried to rename midi karaoke files to midi files,

forfiles /S /M *.kar /C “cmd /c rename @file @fname.mid”

This doesn’t work if the file name has spaces in it, (OS Win XP Sp3).
But I found other solution that works flawlessly

FOR /R %f IN (*.kar) DO REN “%f” *.mid

For more info:


Leave a Comment

HTML tags are not allowed.

Previous post:

Next post: