Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
How do I prompt for a user to input an integer in DOS and then execute a loop depending on the number of integer entered ?
Pls help.

Hi,
This should work in most DOS from 5.0 up and in w2k/XP.
::
@echo off > quit.bat
choice /c:123456789 Enter an integerif errorlevel 9 goto 9
if errorlevel 8 goto 8
if errorlevel 7 goto 7
if errorlevel 6 goto 6
if errorlevel 5 goto 5
if errorlevel 4 goto 4
if errorlevel 3 goto 3
if errorlevel 2 goto 2
if errorlevel 1 goto 1:9
set NUMloops=*********
goto process:8
set NUMloops=********
goto process:7
set NUMloops=*******
goto process:6
set NUMloops=******
goto process:5
set NUMloops=*****
goto process:4
set NUMloops=****
goto process:3
set NUMloops=***
goto process:2
set NUMloops=**
goto process:1
set NUMloops=*
goto process:process
echo NUMloops=%NUMloops%
set loopNUM=:loop
if %NUMloops%'==%loopNUM%' quit::**********************************
:: The thing to be done goes here
::**********************************
set loopNUM=%loopNUM%*
echo %loopNUM%
goto loop::**
HTH
M2If at first you don't succeed, you're about average.

Nobody is obligated to say thank you, but it would be a REAL good idea to at least say if the batch worked.
M2If at first you don't succeed, you're about average.

Hi M2,
Sorry for the late reply.Got tied up with other things @work.
Hey, you're genius! Your script does work for my bath file.I truly got to thank you for saving my day.
Regards,
Smileguy

Hi M2,
Sorry again, I would greatly appreciate to learn how can the batch display the number of loops on screen instead of just "*" ?
Thank you in advance.

Hi,
Modify blocks:
:: OLD
:9
set NUMloops=*********
goto process
:::: NEW
:9
echo 9
set NUMloops=*********
goto process
::
M2If at first you don't succeed, you're about average.

Thanks M2!
But what i'm referring to will be this portion as shown below:
.
.
.
set loopNUM=%loopNUM%*
echo %loopNUM%
goto loop
How can I possible display %loopNUM% to be shown as the integer instead of '*" ?Thank you.

Hi,
In NT we could have cut this down considerably, but to work in DOS, which 'doesn't do' command line math:
::**
if %loopNUM%'==*' echo 1
if %loopNUM%'==**' echo 2
...
::**It's messy but it works.
M2If at first you don't succeed, you're about average.

Hi M2,
I'm just exploring further improvements on the above batch script.Well, the above script process a user's choice for FTP command (3M file download test , 5 M file download test, etc) and prompt for number of loop to execute.
Well, the above portion has been settled.It works.
However, my main challenge is how to include date and time stampings against their coresponding ftp results and format the output nicely to a text file row by row ?
Eg :
Sat 02/04/05 23:59 - ftp: 2742001 bytes received in 13.69Seconds 200.29Kbytes/sec.
Sat 02/04/05 00:01 - ftp: 2742001 bytes received in 12.23Seconds 235.04Kbytes/sec.
:
:
:I would greatly appreciate your help in this.
Thanks, M2.

For the above, I can settle the date and time stamping output to a text file and also i can use the 'find' command to extract the ftp results and output to the same txt file as the date/time.But, i simply unsure how to format them nicely row by row.
Please help.Thanks.

Hi,
While you're doing all these looped ftp transfers, and burning up bandwidth, try to keep in mind that folks on the bottom end of the food chain get 5KB/s on the best of days.
Teah, problem is when you echo or pipe the date/time and the find output to a file, each append adds a 'line break'.
CRLF [0d0a hex]
So you need to chop out the 0d0a. To use only DOS/NT it comes down to DEBUG.
So, your choice, DEBUG or a 3rd party utility.
M2If at first you don't succeed, you're about average.

Sorry M2,
But i don't quite understand yr reply.
if i want to use the DOS Debug, how am i going to sort to format my output results row by row?
If it's ok for me to email to you my DOs batch file, i would appreciate it.
Thanks.
Regards,
Smileguy

Hi SmileGuy,
You're welcome to email your BAT.
15583@dodgeit.com
Either way, we'll 'keep it public'; the assumption being that many others are reading and learning.
Sorry to take so long; had to go to Burma today [!].
Didn't mean to 'baffle with brilliance'
.Each time you ECHO or PIPE into a file you get, along with the desired text, a 'line break', commonly called CRLF or 0d0a.
So the file 'looks like' separate lines.
This is not what you want. As per you example, you want each line to have:
date time somestring
So we need to get rid of the 'line breaks'.
A third party util works as well but frustrates using the script on a box which does not have the utility. So we'll use DEBUG.
This BAT will put the date and time and the output of your FIND into a file with all that on one line and append it to MYBIG.LOG
***
Does this need to work in NT & DOS?
M2If at first you don't succeed, you're about average.

Hi M2,
I've already emailed the .bat files to your email.
Hope you've received them.
Thank you.
Smileguy

S g,
Can't connect right now.
I'll keep trying
M2
If at first you don't succeed, you're about average.

Hi,
I got the mail but it's all junked up with html.
Zip it up and send it to:
15583zip
at
thaiguides
dot
com
M2
If at first you don't succeed, you're about average.

Hi smileguy,
I had MailWasher set to block ZIPs.
The filter is now off.
Send your ZIP again.
Regards,
M2
If at first you don't succeed, you're about average.

Hi,
I'm getting some errors with your bat, but I see the way forward.
This shows all your "FINDs":
find /I "current" time.txt >> R3m.txt
find /I "current" date.txt >> R3m.txt
find /I "Kbytes/sec" d3m.txt >> R3m.txt
find /I "current" time.txt >> R50m.txt
find /I "current" date.txt >> R50m.txt
find /I "Kbytes/sec" d50m.txt >> R50m.txt
find /I "current" time.txt >> R3UP.txt
find /I "current" date.txt >> R3UP.txt
find /I "sent" d3UP.txt >> R3UP.txtWith those FINDs you wind up with lines like"The current..."
When all you really want is the time and date and the ftp result on one line.
The first instance I see where you use %time% is on line #111:
set timestamp=%date% %time%
This will not work in DOS without first setting the TIME var.
If you are setting the TIME & DATE vars separately, we need to know how they are laid out. In particular, it will help to:
echo %time% %date%>TDfile
and report the file size.
M2
If at first you don't succeed, you're about average.

Hi M2,
Thanks for yr comment.
Howeveer, I'm aware of the search for my "find" command.But, i'm just wondering how can i format the results into proper row with date/time on the corresponding results?
Also, for the the Kbytes/s , how to convert to kbits/s by multiplying by 8.Can DOS do it?

Hi SmileGuy,
I'm still not clear on how [or if] you are getting DATE & TIME into vars.
***
echo %time% %date%>TDfileand report the file size.
***As to math in DOS, it's pretty much no-go.
M2
If at first you don't succeed, you're about average.

Hi M2,
Ideally, i would like my text output to be as follow :-Sample
-------- S------------ D3M.TXT
Mon 04/04/2005 22:37 hrs - ftp: 2742001 bytes received in 14.57Seconds 188.18Kbytes/sec.
Mon 04/04/2005 22:38 hrs - ftp: 2742001 bytes received in 13.37Seconds 205.10Kbytes/sec.
Mon 04/04/2005 22:39 hrs - ftp: 2742001 bytes received in 13.31Seconds 206.03Kbytes/sec.
Mon 04/04/2005 22:40 hrs - ftp: 2742001 bytes received in 13.63Seconds 201.17Kbytes/sec.
Mon 04/04/2005 22:41 hrs - ftp: 2742001 bytes received in 13.36Seconds 205.24Kbytes/sec.
--------------

Hi,
Yes, I thought that's where were going.
Don't want to sound like a broken record but we need to get clear about the TIME & DATE vars.
M2
If at first you don't succeed, you're about average.

Hi M2,
The DATE & TIME vars are taken from system stamping.
If the way I retrieve my date/time is not refined, I'm open to your suggestion.
Thanks.
Smileguy

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |