Changing File Extensions with REN.

Changing File Extensions with REN.

This document will demonstrate how to change the file extensions of a batch of files automatically. This may be helpful if you have a large number of images that are in the wrong file format, and you need to convert them.


What is REN?

REN is a command that is used for renaming files through the command prompt. It has many utilities aside from renaming file extensions, but for our purposes we will focus on the file extension portion.

How to use REN to change a batch of file extensions.

From the command prompt, REN is entered followed by 2 parameters, the first being the file or folder that you wish to change, the second being what you want to change to. N example can be seen below:

REN file.exe file.txt

Spaces are used to separate the command and the two parameters. The example above is looking for “file.exe” in the main directory, but let’s say you want to change files in a specific folder. To do this you will specify the folder pat in the 1st parameter.

REN C:\Users\kyle\Desktop\folder\file.exe file.txt

This methods choose a specific file from a specific folder, but let’s say you need to change the file extension if many different file name. This is where command wild cards come in. There are two wild card, “*” and “?”. We can ignore the question mark for now, as we will only need the star. See below how the wild card should be used to change multiple files:

REN C:\Users\kyle\Desktop\folder\*.exe *.txt

The statement above will take every file in the folder with an .exe extension and change it to .txt. You can be even broad by using an additional wild card:

REN C:\Users\kyle\Desktop\folder\*.* *.txt

The command above is changing any file in the folder to a .txt file.

Finally, let’s say the images are in subfolders for each home. While the REN command can change file names for every file in a folder, additional logic will need to be added to recursively perform this command for all sub folders. See below:

FOR /R “C:\Users\kyle\Desktop\FolderWithSubdirectories” %f IN (*.*) DO REN “%f” *.txt

The /R is a recursive command that will cycle through and perform REN for all folder in the directory. Note the new location of *.* and *.txt