The Command Prompt is a powerful tool built into most computers running the Windows operating system. It is a command line interpreter that you can use to perform just about any task, including things like renaming files.
While you can also rename files through File Explorer, doing so in Command Prompt can be much faster if you know how. Additionally, you can also batch rename files in the Command prompt which can massively increase your efficiency.
Rename Files on Command Prompt
The simplest way to rename files in Command Prompt is by going to that specific file’s directory and using the ren/rename
command. Its syntax is rename filename newname
.
When using it practically, replace the filename with the file’s actual name and newname with the name you want to set. You can also use ren
instead of rename as both are the same command.
However, before you go on to use the command, there are a few things to keep in mind.
- You will need to include the file name extension in your command, as your terminal will display an error if you don’t. (If you’re renaming folders, you don’t need to do so.)
- You also need to specify the filename extension for your newname. If you don’t, the newly renamed file will have no extension.
- If your filename or newname contains spaces, you will need to enclose them within double quotation marks.
Now that you know the basic rules to follow when using the rename command, here’s how you can go about using it.
- Press Windows key + R key to launch Run box.
- Type
cmd
and press Enter. - In Command Prompt, you will need to change the active directory to the location of the file you want to rename. To do so:
- Enter the
command cd <file location path>
. - If the file you want to rename is in another drive instead of default
C
, you will first need to change to that specific drive. To do so, enter the drive letter followed by:
For example,D:
- If you don’t know how to get the file location path, navigate to the file’s location in File Explorer, and simply copy the location available in the address bar.
- Enter the
- Now, enter the command
rename filename newname
. (For example,rename Untitled.docx Schedule.docx
) - You can also use the same command to rename file name extensions. (For example,
rename Schedule.docx Schedule.txt
)
Additionally, if you don’t like using the cd command to change your active directory, there is another method you can use. Navigate to the file location in File Explorer, type cmd
in the address bar and press Enter. This will directly open Command Prompt in that directory.
Alternatively, you can tweak the rename command a little so that you don’t have to change your directory to rename files. The syntax for this altered command is rename “file path location” newname
.
For example, rename “C:\Screenshots\20190213.jpg” “Sun Tzu Quote.jpg”
Batch Rename Files on Command Prompt
The best use of the rename command is when you’re trying to rename many files simultaneously. To batch rename files in the Command prompt, you will have to know about the two key wildcards, *
and ?
.
Using * Wildcard
The *
character is basically used to select all the files at once, but it is low in priority order. For example, the rename Photo*.jpg Image*.jpg
will change any image file beginning with the name Screenshot to Image with the same characters following after.
In a nutshell, if your images were labeled Photo1, Photo2, and so on, the above command will change them to Image1, Image2, and so on.
If you want to rename files without having to specify their extensions, you can use the *
wild card to do so as well. For example, rename Untitled.jpg Image.*
will make sure that your renamed file has the same extension as its earlier version.
Also, you can use the *
wildcard to rename all files with a particular extension to another extension. For example, rename *.txt *.docx
will make sure any files with the .txt
extension will get renamed to .docx
.
Using ? Wildcard
The ?
character can be used as a placeholder to replace itself with the character in the same position as itself. You can use this character in conjunction with the *
character to batch rename files and trim specific files.
For instance, the rename *.* ?????.*
will trim every file to its first five characters. You can add or remove as many ?
wildcards to expand or lower the character count.
Also, you can specify the extension in the filename to only target specific files. For example, rename *.jpg ?????.*
will trim every jpg file to its first five characters.
Another way you can use this ?
wildcard is at the filename to specify files with varying lengths of name characters. For instance, the rename “?????.jpg” “?????2022.*”
will add 2022 to every jpg file that has five characters in its name.
If you’d like a more in-depth explanation on batch renaming files and wildcard characters, you can check out our other article.