How to replace the file extensions of several files

Updated: 03/06/2020 by Computer Hope
replace file extension

It 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 (Active Server Pages) file to an HTML (hypertext markup language) 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. To change the file type, you need to convert the file. With an ".exe" file and other file extensions, you may need to use a program to create the file.

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 following steps.

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 lets you 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

To rename the extensions without keeping the original file, you can also use a command similar to the following example.

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.

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

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

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 using the mv (move) command as shown.

mv hope.txt hope.html

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