Windows operating systems provide the rename
command which is used to rename files and folders. The rename command can be used via the MS-DOS (cmd.exe) command prompt or PowerShell command-line interface. But the rename command is popular with the MS-DOS command-line interface. In this tutorial, we examine how to rename a file relatively, absolutely, or in different partitions.
rename Command Syntax
The rename command has the following syntax where the source file is specified firstly and then the destination or new name of the file is specified secondly.
rename SOURCE NEWNAME
- SOURCE is the current file name.
- NEWNAME is the new name of the SOURCE file.
Rename File
We start with a simple example where we rename or change the name of the file named myfile.txt
. The new name of the “myfile.txt” will be “release.txt”.
rename myfile.txt release.txt
Rename File with Absolute Path (Complete Path)
A file name can be changed with its abosulte path. The current file is specified with its complete or absolute path. The new name can be specified relatively or absolutely. In the following example we rename the “c:\myfile.txt” into “release.txt”.
rename "C:\myfile.txt" "release.txt"
Alternatively the new name or new file can be specified absolutely or with its complete path like below.
rename "C:\myfile.txt" "c:\release.txt"