Command Prompt/Batch - rename multiple files with sequential numbering
@echo off
setlocal EnableDelayedExpansion
set filename=FileTitle
set suffix=100
for /F "delims=" %%i in ('dir /B *.txt') do (
set /A suffix+=1
ren "%%i" "%filename%-!suffix:~1!.txt"
)
This code renames the files in the form you requested. Note that the numeric suffix have two digits in order to preserve the original alphabet order of the files. If "natural" 1-99 numbers were used, then the order in that cmd prompt show the files is changed in this way: 1.txt 10.txt 11.txt ... 19.txt 2.txt 20.txt 21.txt ... 29.txt 3.txt ...
(alphabet order, NOT numeric one). If may be more than 99 files, just add another zero in set suffix=100
command to generate a three-digits suffix.
Note also that your plain for
command may process some files twice or more times depending on the site where the renamed files will be placed in the original files list. To avoid this problem use a for /F
command over a dir /B *.txt
one. This method first get a list of all files, and then execute the renames over such a static list.
To process all files under current folder (that is the purpose of your /r
switch in for
command), just add a /S
switch in the dir
command.