Slight typo there. Missed a % off the progname variable:
@echo off
set selection=%1
set menufile=menu.txt
if "%selection%"=="" call :choose
if "%selection%"=="" echo No program selected & goto end
set progname=
for /f "tokens=1,2 delims=," %%a in (%menufile%) do if "%%a"=="%selection%" set progname=%%b & goto next
:next
if "%progname%"=="" echo Program number %selection% not found in list & goto end
start %progname%
goto end
:choose
echo Please choose one of the following programs by pressing the number then Return
echo.
type %menufile%
echo.
set /p selection=Please enter program number and Return:
:end
Main Topics
Browse All Topics





by: dragon-itPosted on 2007-07-06 at 12:55:46ID: 19434509
One possible solution is to use a text file arranged something like this
1,Program1.exe
2,Program2.exe
3,program3.exe
Then a batch file as
@echo off
set selection=%1
set menufile=menu.txt
if "%selection%"=="" call :choose
if "%selection%"=="" echo No program selected & goto end
set progname=
for /f "tokens=1,2 delims=," %%a in (%menufile%) do if "%%a"=="%selection%" set progname=%%b & goto next
:next
if "%progname"=="" echo Program not found in list & goto end
start %progname%
goto end
:choose
echo Please choose one of the following programs by pressing the number then Return
echo.
type %menufile%
set /p selection=Please enter program number and Return:
:end
This would check for the number matching a program in the text file and if it does then execute the program otherwise if no argument is given then show the text file and request entry of a number.
Steve