Solved

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

Posted on 2003-10-22
3
550 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

NTFS file system has been developed by Microsoft that is widely used by Windows NT operating system and its advanced versions. It is the mostly used over FAT file system as it provides superior features like reliability, security, storage, efficienc…
Possible fixes for Windows 7 and Windows Server 2008 updating problem. Solutions mentioned are from Microsoft themselves. I started a case with them from our Microsoft Silver Partner option to open a case and get direct support from Microsoft. If s…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

756 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