Link to home
Start Free TrialLog in
Avatar of TheShaner
TheShaner

asked on

Batch file looping

Can someone show me how to work loops in a DOS batch file?  At the most basic level, I could give the following example.

Loop using a counter..  A do while if you will.  I guess an easy example would be something like this.  

Create 50 directories.  All with the same name, only with a number at the end of it.  And stop when I hit 50

server1
server2
server3
etc.

Also, does anyone know any good reasources for learning this kind of stuff?  I am pretty handy in writing batch files, but would really like to take things to the next level and add some real complexity to them.

Thanks,

Shaner

Avatar of Steve Knight
Steve Knight
Flag of United Kingdom of Great Britain and Northern Ireland image

Easiest way for that is

for /l %%a in (1,1,50) do mkdir server%%a

for /? gives a mine of information as does set /?

I learned the more complex stuff watching here to be honest.

Steve
ASKER CERTIFIED SOLUTION
Avatar of Steve Knight
Steve Knight
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
More usefull stuff in if /? and cmd/? for starters.

Steve
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
the most basic loop would be this:

:START
(whatever you want to be looped)
GOTO START
thanks for the answer, hope it helped.

Steve