The use of Ren is simple. The format is: New File Name of old Ren file. For example, change test.txt to abc.txt and use Ren test.txt abc.txt.
You must note that the old file can use an absolute or relative path. However, the new file name cannot use any path, but can only be a new file name, even if the path is the current directory. For example, if the name of the file D: \ test \ abc.txtis xyz.txt, if the current path is D: \ test, the command can be written as: Ren abc.txt xyz.txt, Ren D: \ test \ abc.txt xyz.txt, however, it cannot be written in the format of Ren D: \ test \ abc.txt. This odd rule may be that once the path is written into another directory, Ren has the "Move file + rename file" function, which is inconsistent with its positioning.
Although Ren is easy to use, its functions are powerful, mainly thanks to its support * and? These two wildcards: * represents any number of characters ,? Represents a character. For example, you need to change all files whose names are suffixed with ". txt" to ". Doc" as the suffix and use "Ren *. TXT *. A simple statement that instantly changes a large number of files. The cmd command is concise and powerful. For example, if you want to rename a TXT file with the ABC string and only five characters as the XYZ string, you can write: Ren ABC ??. Txt xyz ??. TXT.
It is important to note that when using wildcard characters, the matching rules of Ren are very strange and too complex, and are not suitable for beginners to understand. Therefore, we will not describe them in detail here. For details, refer to this post: Is this a bug of Ren? Http://www.cn-dos.net/forum/viewthread.php? Tid = 29538. If you really need wildcards, you are advised to read this post carefully. If it is hard to understand, you can go back to the next step and only use wildcards to modify the suffix. You do not need to delve into these complex rules.
Ren also has a very strange property: When a file has a hidden property or system property, Ren does not work. You need to hide the file or remove the system property to rename the file, rename a read-only file. This has often caused us a lot of trouble: When you don't know whether the file you want to rename has hidden or system attributes, it is very difficult to directly rename the file ,; if you want to keep the original file attributes when renaming a file, it is even more painful.
What should I do?
If you don't mind whether the attributes of the file are modified, the safe way is to use the attrib-s-h command to remove the possible system attributes or hidden attributes of the file, and then Renzhi; if you want to keep the original attributes of the renamed file, use % ~ in the for statement first ~ AI extension obtains the attributes of the original file, saves them to the variables after processing, and then uses attrib-s-h to remove the possible system attributes or hidden attributes of the file. After Ren, then read the attribute values retained in the variable and restore the original file attributes with attrib.
Ren also applies to folders.