Solved

How to have batch file repeats two or more lines for "x" times?

Posted on 2003-10-22
3
548 Views
Last Modified: 2013-12-29
Is there a way I can repeat two or more lines of a batch file in
Win98SE without retyping the same code?

0
Comment
Question by:happycat
  • 2
3 Comments
 
LVL 59

Accepted Solution

by:
LeeTutor earned 100 total points
ID: 9600240
You can program loops in batch files, like so:

:Toploop

(statements to repeat go here)
goto Toploop

Unfortunately this sort of thing is an "infinite" loop (repeating until you use the Ctrl-C key combination to exit it) unless you have some sort of test for when to exit the loop before the "goto" statement.

Back in 1988, Pc Magazine published a book called "Pc Magazine DOS Power Tools Techniques, Tricks and Utilities", by Paul Somerson, that included a floppy disk with many assembly language routines to enhance DOS, including a program called LOOP.COM which incremented a counter that the IF ERRORLEVEL batch statement can test.  So, say you wanted to have a loop execute 15 times.  It would look like this:

Loop /s
:Toploop

(statements to repeat go here)
Loop
if not errorlevel 15 goto Toploop

The first "Loop /s" statement must be above the loop, to initialize the count to zero. The Loop statement within the loop just increments the count.

There are many other useful utilities written about in this book, too.  Where can you get it?  I found one place, where apparently you can buy this 1274 page book (!) for only 50 cents, used.  Unfortunately, the floppy disk that the utilities come on are on the old 5 1/4" floppy, not today's 3 1/2" floppy.  Maybe you can find an old computer that uses that sort of floppy drive as well as the smaller and then copy from one to the other.  Or, I could send you a copy of the program in an attachment if you put your email address in your profile.

http://www.amazon.com/exec/obidos/search-handle-url/index%3Dbooks%26field-keywords%3Ddos%252520power%252520tools%26store-name%3Dbooks/104-7162452-4822318
0
 

Author Comment

by:happycat
ID: 9601158
Thanks. I just figured out the goto command and how to label a line.
Yes it is infinite loop so your other comments are very helpful. Very well written.


0
 

Author Comment

by:happycat
ID: 9601170
LeeTutor, if you will that attachment would be great. Check profile for email, Thanks.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
outlook and exchange information 3 35
Elderly Mom computer-how to use her computer to monitor her health 4 32
server core and windows updates 3 40
Thoughts on PC Doctor 11 50
Storage devices are generally used to save the data or sometime transfer the data from one computer system to another system. However, sometimes user accidentally erased their important data from the Storage devices. Users have to know how data reco…
While rebooting windows server 2003 server , it's showing "active directory rebuilding indices please wait" at startup. It took a little while for this process to complete and once we logged on not all the services were started so another reboot is …
With the advent of Windows 10, Microsoft is pushing a Get Windows 10 icon into the notification area (system tray) of qualifying computers. There are many reasons for wanting to remove this icon. This two-part Experts Exchange video Micro Tutorial s…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…

825 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question