How to replace the file extensions of several files

Updated: 01/24/2018 by Computer Hope

replace file extensionIt may be necessary to rename several file extensions to allow compatibility with another program. A good example where this could be used is renaming an ASP file to an HTML file.

Note: It is important to realize that you cannot rename a file extension and change the type of a file. For example, you cannot rename a file with a .txt extension to a .jpg and make it an image or a .exe file and make it executable. If you want to change the file type, you need to convert the file. In the example of a .exe file and other file extensions, you may need to use a program to create the file or save the file as a different file extension.

Renaming in MS-DOS and the Windows command line

To rename file extensions from the Windows command line, open the command prompt and follow the steps below.

Rename a file extension keeping the original

Use the below 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.

Rename and replace files with a file extension

If you want to rename the extensions without keeping the original file, you can also use a command similar to the example below.

rename *.shn *.wav

Rename a single file and extension

If you are only want to rename a single file and extension, you can specify the full file name and file extension as shown below.

rename hope.txt hope.html

In the example above, the "hope.txt" text file would be renamed to "hope.html".

Rename a single file with the move command

Just like using the rename command, you can also use the move command to rename a file as shown below.

move hope.txt hope.html

In the example above, the "hope.txt" text file would be renamed to "hope.html".

Renaming in Linux

In the Linux command line, you can rename a file and file extension by using the mv (move) command as shown below.

mv hope.txt hope.html.

In the example above, the "hope.txt" text file would be renamed to "hope.html".

Additional information