9. The 'REN' or 'RENAME' function

To start, the 'REN' command has a bug: in special cases files get renamed twice (or even three times). We avoid that by a trick (see chapter 10).

9.1 Change subdirectory name

Perform this command:
D:\test>REN "my Doc" "my Doc Backup" [ENTER]
Type
D:	est>DIR [ENTER]
and you'll see that the subdirectory 'my Doc Backup' exists and 'my Doc' doesn't. Remember that it is a good idea to surround 'names' with space(s) by double quotation marks (double apostrophes).

An alternative command is:
D:\test>MOVE "my Doc" "my Doc Backup" [ENTER]

9.2 Change the file extensions in the current directory

A simple example: change the extension '.txt' into '.dat'
D:\test>REN file3.txt file3.dat  [ENTER]
In case of a bulk rename, you should write at the prompt
D:\test>REN *.txt *.dat  [ENTER]
It means that all files with extension '.txt' will get the extension '.dat'.

To change the extension of every (!) file, use
D:\test>REN * *.txt  [ENTER]

9.3 Modify filenames in the current directory: basic examples

To change the filename 'file1.txt' into 'file1_1.txt', type:
D:\test>REN file1.txt file1_1.txt [ENTER]
The '.txt' files in our example directory have the filenames: 'file1.txt', 'file2.txt' and 'file3.txt'. To uppercase the first letter 'f' of these filenames:
D:\test>REN f*.txt F*.txt [ENTER]
Swap the parameters to lowercase the first character of a filename.

Use the wildcard ? to change the first letter of filenames with the extension '.txt'.
D:\test>REN ?*.txt T*.txt [ENTER]
So 'file1.txt' will be renamed into 'Tile1.txt'.

Use the wildcard ?? for the change of the first two letters of filenames with the extension '.txt':
D:\test>REN ??*.txt Ta*.txt [ENTER]
So 'file1.txt' will be renamed into 'Tale1.txt'.

Change the second letter of filenames with the extension '.txt':
D:\test>REN ?i*.txt ?a*.txt [ENTER]
So 'file1.txt' will be renamed into 'fale1.txt'.

Notice that
D:\test>REN *i*.txt *a*.txt
with an * at the beginning of the pattern will not work. To replace the letter 'i' by an 'a' regardless its position, we have to use the 'FOR' loop (Chapter 10).

9.4 Truncate a filename by using ?

The command
D:\test>REN ???*.txt ???.txt [ENTER]
truncates the filename of all '.txt' files to the first three characters (three question marks ???). So: '1_file.txt' will be '1_f.txt'.

9.5 Modify filenames in the subdirectory 'my Doc': basic example

To rename 'doc 1.rtf' to 'doc_1.rtf' in subdirectory 'my Doc':
D:\test>CD "my Doc" [ENTER]
D:\test\my Doc>REN "doc 1.rtf" doc_1.rtf [ENTER]
Of course, this can be done in one command as well:
D:\test>CD "my Doc" & REN "doc 1.rtf" doc_1.rtf [ENTER]
or
D:\test>REN "my Doc"\"doc 1.rtf" doc_1.rtf [ENTER]