Purpose:Rename files or subdirectories


Format:REN [/A:[[-][+]rhsadecijopt] /B /E /I"text" /N[enst] /O:[-]adegnrstu /P /Q /S /T] [@file] old_name... new_name


RENAME [/A:[[-][+]rhsadecijopt] /E /I"text" /N[enst] /O:[-]adegnrstu /P /Q /S /T] [@file] old_name... new_name


old_nameOriginal name of the file(s) or subdirectory.
new_nameNew name to use, or new path on the same drive.
@fileA text file containing the names of the source files to rename, one per line (see @file lists for details).


/A: (Attribute select)/O:... (Order)
/B (Rename on reboot)/P(rompt)
/E (No error messages)/Q(uiet)
/I"text" (match description)/S(ubdirectory)
/MD (Create target directory)/T(otal)        

/N (Disable)


See also: COPY and MOVE.


File Selection:


Supports attribute switches, extended wildcards, ranges, multiple file names, delayed variable expansion, and include lists. Use wildcards with caution on LFN volumes; see LFN File Searches for details.


Internet:  Can be used with FTP/HTTP Servers and HTTP/HTTPS servers.




REN and RENAME are synonyms. You may use either one.


REN lets you change the name of a file or a subdirectory, or move one or more files to a new subdirectory on the same drive. New files may be on different file systems or drives; new directories must be on the same drive.


In its simplest form, you give REN the old_name of an existing file or subdirectory and then a new_name. The new_name must not already exist; you can't give two files the same name (unless they are in different directories). The first example renames the file MEMO.TXT to MEM.TXT. The second example changes the name of the \WORD directory to \WP:


rename memo.txt mem.txt

rename /s \word \wp


When you rename files or directories on an LFN drive, you must quote any names which contain white space or special characters.


You can also use REN to rename a group of files that you specify with wildcards, as multiple files, or in an include list. When you do, the new_name must use one or more wildcards to show what part of each filename to change. Both of the next two examples change the extensions of multiple files to .SAV:


ren config.nt autoexec.nt tcstart.btm *.sav

ren *.txt *.sav


REN can move files to a different subdirectory on the same drive. When it is used for this purpose, REN requires one or more filenames for the old_name and a directory name for the new_name:


ren memo.txt \wp\memos\

ren oct.dat nov.dat \data\save\


The final backslash in the last two examples is optional. If you use it, you force REN to recognize the last parameter as the name of a directory, not a file. The advantage of this approach is that if you accidentally mistype the directory name, REN will report an error instead of renaming your files in a way that you didn't intend.


REN can also move files to a new directory and change their name at the same time if you specify both a path and file name for new_name. In this example, the files are renamed with an extension of .SAV as they are moved to a new directory:


ren *.dat \data\save\*.sav


If you use REN to rename a directory, the new_name must normally be specified explicitly, and cannot contain wildcards. You can override this restriction with /S.


You can also rename a subdirectory to a new location in the directory tree on the same physical drive (sometimes called "prune and graft"). You must specify the new name explicitly, not just give the path. For example, if the D:\TCMD directory contains a subdirectory TEST, you can rename TEST to be a subdirectory of the root directory like this:


[d:\tcmd] ren TEST \TEST\


REN does not change a file's attributes, except to set attribute A. The new_name file(s) will have the same attributes as old_name.


If you have appropriate permissions, you can rename files on FTP, HTTP, and HTTPS servers. For example:


ren ftp://ftp.abc.com/file1.txt file2.txt


Wildcard characters like [*] and [?] will be treated as wildcards in FTP URLs, but will be treated as normal characters in HTTP URLs.


You can also use the IFTP command to start an FTP session on a server, and then use an abbreviated syntax to specify the files and directories you want. For more information, see Using FTP/HTTP Servers and IFTP.


REN supports regular expression back references in the target name. If you are using back references, you must also use a regular expression in the source name. The syntax is:


ren ::filename ::target


REN sets three internal variables:


%_ren_dirsThe number of directories renamed
%_ren_filesThe number of files renamed
%_ren_errorsThe number of errors


Note: The wildcard expansion process will attempt to allow both CMD-style "extension" matching (assumes only one extension, at the end of the word) and the advanced TCC-RT string matching (allowing things like *.*.abc) when an asterisk is encountered in the destination of a REN command.




/A:Rename only those files that have the specified attribute(s) set. See Attribute Switches for information on the attributes which can follow /A:. Do not use /A: with @file lists. See @file lists for details.


You can specify /A:= to display a dialog to help you set individual attributes.


/BIf REN can't rename the file (i.e., access denied), it will schedule it to be renamed at the next reboot.


/ESuppress all non-fatal error messages, such as "File Not Found."  Fatal error messages, such as "Drive not ready," will still be displayed. This option is most useful in batch files.


/I"text"Select files by matching text in their descriptions. The text can include wildcards and extended wildcards. The search text must be enclosed in double quotes, and must follow the /I immediately, with no intervening spaces. You can select all filenames that have a description with /I"[?]*", or all filenames that do not have a description with /I"[]". Do not use /I with @file lists. See @file lists for details.


/MD Create the target directory if it doesn't exist. Note that you *must* either terminate the target directory name with a trailing \ or specify a filename component; otherwise REN cannot tell what you want for the directory and what you want for the filename.


/NDo everything except actually rename the file(s). /N displays how many files would be renamed. This option is useful for testing what a REN command will actually do.


A /N with one or more of the following arguments has an alternate meaning:


eDon't display errors.
nDon't update the file descriptions
sDon't display the summary


/O:...Sort the files before processing.


You may use any combination of the sorting options below. If multiple options are used, the listing will be sorted with the first sort option as the primary key, the next as the secondary key, and so on:


nSort by filename and extension, unless e is explicitly included. This is the default.
-Reverse the sort order for the next sort key
aSort names and extensions in standard ASCII order, instead of numerically when numeric substrings are included in the name or extension.
dSort by date and time (oldest first); also see /T:acw
eSort by extension
gGroup subdirectories first, then files
rReverse the sort order for all options
sSort by size
tSame as d


The /O:... option saves all of the matching filenames and then performs the rename. This avoids the potential problem of renaming files more than once.


/PPrompt the user to confirm each rename operation. Your options at the prompt are explained in detail under Page and File Prompts.


/QDon't display filenames  or the number of files renamed. When used in combination with the /P option above, it will prompt for filenames but will not display the totals. This option is most often used in batch files. See also /T.


/SNormally, you can rename a subdirectory only if you do not use any wildcards in the new_name. This prevents subdirectories from being renamed inadvertently when a group of files is being renamed with wildcards. /S will let you rename a subdirectory even when you use wildcards. /S does not cause REN to process files in the current directory and all subdirectories as it does in some other file processing commands. To rename files throughout a directory tree, use GLOBAL REN.


/TDon't display filenames as they are renamed, but report the number of files renamed. See also /Q.