0% found this document useful (0 votes)
49 views6 pages

Starten: Rename File Extensions in Bulk, Including Files in Subfolders

including files in subfolder

Uploaded by

B Prakash Sharma
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
49 views6 pages

Starten: Rename File Extensions in Bulk, Including Files in Subfolders

including files in subfolder

Uploaded by

B Prakash Sharma
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Rename file extensions in bulk, including files in subfolders

Bulk Rename Files

2/21/2015

Windows Download

Windows 7

Batch Rename

Windows Command Line


Windows command line, Windows 7, Windows 8, XP, Server 2003, 2008, Vista

Rename file extensions in bulk, including files in


subfolders
by admin on July 3, 2012

Download
starten
Kostenloser Sofort-Download
Schnell & einfach!

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 cant use it to rename file extensions recursively in the sub folders. Next, well 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"

http://www.windows-commandline.com/rename-file-extensions-bulk/

1/6

Rename file extensions in bulk, including files in subfolders

2/21/2015

Handling names with white spaces


If the new name you want to assign to the files has white space within it, it can be done by adding double quotes around the file name.
So that forfiles does not misinterpret this doublequotes, you need to escape them with \
For example to add pic.jpg to each of the jpg files, the command would be as below.
forfiles /M *.jpg /C "cmd /c rename @file \"@fname - pic.jpg\""

Additional Reading...
Batch file : How to get current directory
Batch file : ECHO command
Windows environment variables
{ 17 comments read them below or add one }
DPS Chawla February 24, 2014 at 5:17 pm
Great Thanks REgards
Reply
atul June 17, 2014 at 11:35 am
thanks for suggestion
Reply
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.
Reply
admin January 14, 2015 at 8:18 pm
This should do
ren *-common.xml *-common.xml.txt

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
Reply
admin January 14, 2015 at 8:20 pm
If you are using forfiles, you donot need to use * again in the cmd part.
forfiles /S /M *-common.xml /C "cmd ren @file @file.txt"

http://www.windows-commandline.com/rename-file-extensions-bulk/

2/6

Rename file extensions in bulk, including files in subfolders

2/21/2015

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
Reply
admin January 9, 2015 at 5:46 am
The file name need to be surrounded with double quotes if it has white spaces. Added example command to the post.
Volker September 25, 2014 at 9:13 am
I have here some files with ending like this
(1).txt
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?
Reply
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.
Reply
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 doesnt 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:


https://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/for.mspx?mfr=true
Reply
Ap.Muthu January 8, 2015 at 6:32 am
None of the websites including this has alluded to the renaming of files by removal a second extension.
If a folder contains several files like *.mo.po and *.mo as file extensions, how do we selectively rename the *.mo.po to *.po whilst
not touching the *.mo that were already there?
Reply
admin January 9, 2015 at 12:18 am
Try this command
forfiles /M *.mo.po /C "cmd /c rename @file @fname"

It works only if you dont have files with the same name and two different extensions.
ex: 1.mo.po and 1.mo. You would get error in renaming as a file already exists with the name.
Let us know if it works for your usecase.
steve szajko January 14, 2015 at 7:44 pm

http://www.windows-commandline.com/rename-file-extensions-bulk/

3/6

Rename file extensions in bulk, including files in subfolders

2/21/2015

A virus added .zwrkocj to all file types, how would I remove that?
Reply
admin January 14, 2015 at 8:15 pm
If it has converted files like file.ext to file.ext.zwrkocj then I think you can run the below to get back to original state.
ren *.zwrkocj *.

cta January 23, 2015 at 5:34 pm


How to append the name of the parent folder onto the prefix of the file name?
Reply
Leave a Comment
Name *
E-mail *
Website

HTML tags are not allowed.


Submit
Previous post: How to kill process on remote computer?
Next post: How to Enable or Disable guest account

Popular Posts
Add user to group from command line (CMD)
How to create large dummy file
Find windows OS version from command line
Add new user account from command line (CMD)
Delete directory/folder from command line
Get mac address from command line (CMD)
Enable remote desktop from command line (CMD)
Xcopy command : syntax and examples
Rename file extensions in bulk, including files in subfolders
Change computer name from command line
Change windows wallpaper from command line
Disable or Enable Windows Automatic updates from command line
Office communicator command line
Windows at command examples
Javac not recognized as internal or external command

Search

E-mail Newsletter
E-mail

Subscribe

Download
starten
http://www.windows-commandline.com/rename-file-extensions-bulk/

4/6

Rename file extensions in bulk, including files in subfolders

2/21/2015

Kostenloser SofortDownload Schnell &


einfach!

2009-2012 Windows-commandline.com The content is copyrighted and may not be reproduced on other websites.

Recent Posts
Internet explorer version updates
Run command for Control panel
Forfiles
Move files and directories to another location
Windows 8 essential commands
Take ownership of file or folder
Find files based on modified time
Javac not recognized as internal or external command
Set path from command line
Search classes in jar file
Find memory size
How to Enable or Disable guest account
Rename file extensions in bulk, including files in subfolders
How to kill process on remote computer?
How to start/stop webclient service
Create event from command line
Sleep command in Windows 7
How to change drive label
Windows 7 Run commands
Format Drive command

Categories
Batch Files (6)
Files (19)
Office Applications (2)
Remote access (4)
System Configuration (11)
System information (9)
Uncategorized (139)
User Accounts (18)
User Settings (2)
Widnows shortcuts (1)
Windows 8 (1)
Windows Commands (28)
WMIC (1)

Recent Comments
needy on Javac not recognized as internal or external command
Bob UK on Xcopy command : syntax and examples
Bob UK on Xcopy command : syntax and examples
http://www.windows-commandline.com/rename-file-extensions-bulk/

5/6

Rename file extensions in bulk, including files in subfolders

2/21/2015

Abdul on Net user command : Manage user accounts from command line
admin on Add user to group from command line (CMD)

http://www.windows-commandline.com/rename-file-extensions-bulk/

6/6

You might also like