Often I need to run an installation script on a database, and then run a series of repeated commands to get data up to date (for example, pre-set a number of rows in a database for timesheeting or creating a number of default entries).  If you’ve got an executable that you need to run a number of times, you can use this command to do it.

for /l %x in (1, 1, <repeat-n-times>) do <command>

where <repeat-n-times> is the number of times you want to repeat, and <command> is the dos command you want to run.

For example, if I wanted to repeat the time 20 times in a row (not sure why this would be useful – but good as an example!):

for /l %x in (1, 1, 20) do echo %date% %time%

If you’re running it in a batch file – then you’ll need two % symbols instead of one, ie

for /l %%x in (1, 1, 20) do echo %%date%% %%time%%

If you have multiple commands for each iteration of the loop, do this:

for /l %x in (1, 1, 20) do (
echo %x
copy %x.txt %x.txt.%x
)