Question Bat file problems. Please help!

May 27, 2019
10
0
10
0
ok.. So I tried to create a bat file that would open a menu the amount of times as you inputted a number ex.

set /p opt= Amount:

Then after that you now have the %opt% set to the "amount" you inputted.
Then the way the menu works is like this..

:start1
if %opt%==0 goto end
:start2
start test.bat
set %opt%-1
if %opt%>0 goto start2

goto end

so that's pretty much the whole script though the marked part doesn't seem to work... Why is that PLEASE HELP!

The entire script...

@Echo off
title screen power...
mode 150
color a

:start
echo please enter the amount of Starts you want.
echo.
set /p opt= Amount:
if %opt%==0 goto end

:begin
start test.bat
set %opt%-1
if %opt%>0 goto begin
goto end

:end
 

gardenman

Distinguished
Moderator

britechguy

Commendable
Jul 2, 2019
1,480
242
1,340
165
GTR is greater than, not equal to.

This loop is arranged to keep going back to begin each time so long as the value of the variable opt is greater than zero. Once it has been decremented to zero, it goes to end. (And it would have done that anyway, with out the "go to :end" statement, given it's position in the script.

One of the best, and most comprehensive, websites when it comes to scripting languages is https://ss64.com/. It's got sections dedicated to many of the most common ones, including command prompt (CMD): https://ss64.com/nt/

Specific to your question, have a look at the compare-ops in the documentation of the IF statement: https://ss64.com/nt/if.html
 

ASK THE COMMUNITY