Renaming Files Using the Command Line

Written by Barry Dysert (last updated June 26, 2017)

7

If you don't mind doing a little more typing and a little less mouse clicking, you can perform a lot of actions from the command line. (Displaying the Command Prompt Window is covered under another tip.) One thing you can do from the command line is rename files. The command-line rename command is REN (or RENAME) and it takes two parameters. The first parameter specifies the file that is to be renamed, and the second parameter specifies what its new name should be.

Let's say you have a file called "C:\Temp\OldFile.txt" and you want to rename it to be "NewFile.txt". You would type the following at the command line:

C:\> REN C:\Temp\OldFile.txt NewFile.txt

Note the fact that the second parameter to the REN command does not include any path information but the first one does. This means you cannot rename a file to a different device or directory.

You can also rename multiple files at once by using the wildcard characters "?" and "*". The "?" character stands for exactly one actual character in the file name; the "*" character stands for one or more actual characters in the file name. So, for example, you can easily rename all of the .tmp files in a given directory to instead be .txt files:

C:\> REN *.tmp *.txt

You can use the "?" to be more specific and/or rename only a part of the file name. Let's say you have several files in a folder and some are named like "file01.tmp", "file02.tmp", "file03.tmp", etc. You just want to rename the "file??.tmp" files to have a ".txt" extension. One way to do this is like this:

C:\> REN file??.tmp file*.txt

You can even rename part of the name piece (regardless of extension) with a little creativity. So if the files to be renamed are like "file01.txt" and "file02.txt" the following command will rename them to "file71.txt", "file72.txt":

C:\> REN file??.tmp file7?.txt

Finally, you can use REN to remove pieces of a file name. Say that you have files named "Jan-numbers.xlsx", "Feb-numbers.xlsx", thru "Dec-numbers.xlsx". You can rename these files to remove the "-numbers" part of the name like so:

C:\> REN ???-numbers.xlsx ???.xlsx

The rename command, especially with wildcards, can be a great timesaver if you're careful with your parameters. Personally, if I want to do anything more sophisticated than the examples presented here I use one of the free file-renamer tools available from various download sites.

 This tip (13085) applies to Windows 7, 8, and 10.

Author Bio

Barry Dysert

Barry has been a computer professional for over 35 years, working in different positions such as technical team leader, project manager, and software developer. He is currently a software engineer with an emphasis on developing custom applications under Microsoft Windows. When not working with Windows or writing Tips, Barry is an amateur writer. His first non-fiction book is titled "A Chronological Commentary of Revelation." ...

MORE FROM BARRY

Understanding Desktop Widgets

Widgets are small, lightweight applications that continually run on your desktop to provide information. You can add, ...

Discover More

Evaluating System Performance Using the Task Manager

One of the many functions of the Windows Task Manager is to allow you to see how your system is performing. If necessary, ...

Discover More

Moving Files Using the Command Line

The MOVE command can be a timesaver over trying to do the similar sort of thing with File Explorer. You can move hundreds ...

Discover More
More WindowsTips

Understanding the Command Line For Loop

A niche command that sometimes comes in handy is the FOR loop. It has several forms and therefore can serve several ...

Discover More

Using the Findstr Command

Finding data within files is a common need. If what you're looking for is in a flat file, you can find what you're after ...

Discover More

Using the Sort Command

Sorting data is a common task even of end users. Fortunately, The Windows command line provides us with a Sort utility so ...

Discover More
Comments

If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] (all 7 characters, in the sequence shown) in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 6Mpixels. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is 8 - 5?

2021-10-01 08:32:40

test test

I ran into an odd issue. I had files that all began with AS and I needed to rename them to CWJS, so what I expected when I ran ren AS* CWJS* was the file AS1234.txt to be renamed CWJS1234.txt, but what I got was CWJS34.txt. It replaced 2 more characters than I expected it to replace. Thoughts on that?


2021-01-17 21:55:49

htsh

How do you delete one character in the filename?


2020-06-18 03:41:20

Garry

What if i want to rename multiple file, which is named 1.txt, 2.txt, 3.txt to 01.txt, 02.txt, 03.txt?
Thank you


2020-05-14 19:17:29

Maxwell Kellogg

Great work. Searched stack overflow for a while but this was by far most put together and easy to use example I found. Thanks!


2019-06-25 04:53:59

hkk

REN ???-numbers.xlsx ???.xlsx

This is awesome!!


2017-08-30 16:35:31

jonathan

I use, Batch Rename Files Tool. You can easily found hier BatchRenameFiles.org that allows you to quickly rename all the files in a specified directory.


2017-07-04 20:21:43

Wilkster

try Krojam Soft Batch Rename program


Newest Tips