MS-DOS Commands :: ren (rename)
Renames a file or files.
Warning: This example is for advanced users only!
How to add a leading zero ("0") to all PDF file names in the currect directory:
Use the following command at the command prompt:
for /f %f in ('dir /b *.pdf') do ren "%f" "0%f"
To use this command in a batch file, replace all the % (single percentage sign) with %% (two percentage signs) as shown below:
for /f %%f in ('dir /b *.pdf') do ren "%%f" "0%%f"
Tip: echo can be used in the above command line in place of ren to see what will be renamed without actually doing the renaming. Change do ren to do echo
Tip: The *.pdf pattern specifies what files are to be renamed. Adjust this pattern as needed to match the files that you wish to rename. For example:
- *.pdf would select all PDF filenames
- ?.pdf would select single character PDF filenames, e.g.: 1.pdf, a.pdf
- ??.mp3 would select two-character MP3 filenames, e.g.: 12.mp3
- ???.txt would select three-character TXT filenames, e.g.: 123.txt
Tip: To add a different prefix other than a leading zero ("0"), change the "0%f" part. For example, to add a prefix of "test-", change "0%f" to "test-%f" (inside a batch file, use "test-%%f").
Warning: Do not try to add a trailing suffix to filenames by using a pattern such as "%f-test". This pattern would rename files incorrectly, such as 1.pdf to 1.pdf-test, rather than to 1-test.pdf
Renames a file or files. RENAME [drive:][path]filename1 filename2. REN [drive:][path]filename1 filename2. Note that you cannot specify a new drive or path for your destination file.
(Enlarge: help ren)