Saturday, February 5, 2011

Enumeration in Batch Files

It's sometimes necessary to enumerate numbers with help of batch files. It may be needful for counting and renaming files, for adding the numbers to lines of different lists in text files, and for dozens of other different purposes. Here is a small script that will help you to enumerate anything you want. Of course, it is not hard to modify this script with help of Dr.Batcher and apply it to your tasks.
for /l %%a in (1,1,999) do (
set n=%%a
call:ch
)
goto:eof
:ch
set "n=000%n%"
set "n=%n:~-3%"
@echo %n%>>1.txt
This script produces 3-characters numbers (i.e. 001, 002, ..., 999) and writes it down to 1.txt. Hope you'll find it useful for some of your batch files.

No comments:

Post a Comment

Translate