Batch Change File Extension

This post talks about how to batch rename file extensions from command line. No 3rd party tools are required. At the end of the post, you can find a download link for the batch file script.

Batch rename file extensions in bulk from CMD

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

Just right-click an empty area of File Explorer, and choose “Undo Rename” from the context menu. Method 2: Batch Rename Multiple Files Using Command Prompt. Another fast way of batch renaming multiple files is using Command Prompt. This method is extremely easy especially if you want to change extensions of multiple files at once. While looking for a way to batch change file extensions I came across an archived thread that states you can use programs like Name Munger to accomplish this. However, I don't think it works to simply change the file name to include a different file extension. I don't believe this gives you a valid extension. Rename a file extension keeping the original. Use the following command at the MS-DOS or Windows command line or within a batch file. Xcopy.shn.wav. Using a wildcard allows you to rename all files with.shn to a.wav, while keeping the original files and extensions. See the xcopy command for further information about this command.

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 batch 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.

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

Remove file extensions in batch

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

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 in batch

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.

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

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.

A: Changing a single file extension in Windows is simple. Just highlight the filename in Windows Explorer and type a new extension after the dot. While this method works fine for a small number of files, manually editing a large number of filenames can take a long time. Fortunately, you can speed up the process through automation by following the steps below.

Batch change file extension

Files in a Single Folder

Below is an example folder with several .TXT files that need to be changed to .XML files.

1. In order to batch rename file extensions, you will first need to open the Windows Command Prompt. To do this, choose Start → Accessories → Command Prompt.

You can also type 'cmd' and press Enter in the Windows Start Menu text field.

Change File Extension Batch Script

2. Navigate to the directory containing the files to rename using the 'cd' command ('cd' stands for 'change directory'). For example, you would type 'cd DesktopXML Docs' to navigate to a folder named 'XML Docs' on the Windows desktop.

Change

3. Type the following command, which will rename all *.txt files in the current folder to *.xml files:

ren *.txt *.xml

The ren command (short for 'rename') provides a simple way to rename one or more files using the Command Prompt. The asterisk (*) in the example above serves as a wildcard character, which is used to rename all files ending in '.txt'.

4. The files are all renamed from *.txt to *.xml:

NOTE: If your files have different extensions, or they do not have an extension at all and you would like to add an extension to them, you can use this command instead:

Batch Change File Extension Windows 10 Powershell

ren * *.xml

Files in Subfolders

Renaming files in subfolders (or subdirectories) is a more complex task that requires additional syntax. The following command uses a loop that iterates through subfolders (one level deep) and changes all file extensions from *.txt to *.xml:

for /d %x in (*) do pushd %x & ren *.txt *.xml & popd

You can replace *.txt and *.xml with any other extensions in the commands above. Also, you can replace *.txt (the first variable) with just * if you want to rename all extensions for all files.

How To Batch Change File Extension

NOTE: Make sure you type the commands above correctly, as you may not be able to undo the renaming process. If you want to be extra safe, you can copy the files to a new folder so that you have a backup of the files before you run the rename command. Once the renaming process completes successfully, you can delete the extra copy of the files.

Batch Change File Type

Updated: October 4, 2012 Simple cmake example c++.