Morning All,
Im currently trying to list the subdirectories as menu options within a batch file.
Ive gotten so far but unable to get menu choices displayed.
What i have so far is:
SET option=1
ECHO.
for /d %%X in (C:\BusNet\Code\armbus\*) do (
SET /a option+=1
ECHO. %option% %%X
)
PAUSE
How ever the option variable does not increment in the FOR loop. CHecking this on completion of the loop it has incremented each time but still displays the origional setting '1'
Once i've got this woking i need a way of transposing the user enetered number back to the corresponding directory.
Any help / suggetsions would be apprecciated.
Thanks
List Directories as Menu Options
Moderator: DosItHelp
Re: List Directories as Menu Options
'
Code: Select all
@echo off &SetLocal EnableExtensions EnableDelayedExpansion
ECHO.
set /a option = 1
for /d %%X in (
"C:\BusNet\Code\armbus\*"
) do (
set /a option += 1
echo. !option! %%X
)
echo. but why ?
pause
SetLocal /?
pause
endlocal
exit /b 0
-
- Posts: 4
- Joined: 05 Sep 2011 02:17
Re: List Directories as Menu Options
Thanks for that Ed.
Works a treat
Works a treat
-
- Posts: 4
- Joined: 05 Sep 2011 02:17
Re: List Directories as Menu Options
OK so i spent a bit more time on this and am at a loss again
I have the directories displayed as menu options. Great
I then prompt for the user to make a choice and attempt to determine which directory this relates to.
The trouble im having is the line:
IF [%CHOICE%]==[!armbusOption!] (SET armbusVersion=%%e & ECHO. SELECTED %%e)
!armbusoption! returns as a negative.
Using the line:
ECHO. !armbusOption! %%e
for debuging i can see that on the 2nd itteration of :armbusVersions armbusOption does not return to ZERO even though the line:
set /a amrbusOption = 0
is present.
Here is what i have so far:
REM @echo off
SetLocal EnableExtensions EnableDelayedExpansion
SET CHOICE=
ECHO. ARMBUS Versions
ECHO.
CALL :armbusVersions
ECHO.
SET /P CHOICE=Select A Version:
CALL :armbusVersions
ECHO.
ECHO. %armbusVersion% Selected
ECHO.
PAUSE
endlocal
exit /b 0
:armbusVersions
set /a amrbusOption = 0
for /d %%X in (
"C:\BusNet\Code\armbus\*"
) do (
SET /a armbusOption += 1
FOR /f "tokens=1-5 delims=\" %%a in ("%%X") do (
IF "%CHOICE%"=="" (
ECHO. !armbusOption! %%e
) ELSE (
ECHO. !armbusOption! %%e
IF [%CHOICE%]==[!armbusOption!] (SET armbusVersion=%%e & ECHO. SELECTED %%e)
)
)
)
GOTO :EOF
I have the directories displayed as menu options. Great
I then prompt for the user to make a choice and attempt to determine which directory this relates to.
The trouble im having is the line:
IF [%CHOICE%]==[!armbusOption!] (SET armbusVersion=%%e & ECHO. SELECTED %%e)
!armbusoption! returns as a negative.
Using the line:
ECHO. !armbusOption! %%e
for debuging i can see that on the 2nd itteration of :armbusVersions armbusOption does not return to ZERO even though the line:
set /a amrbusOption = 0
is present.
Here is what i have so far:
REM @echo off
SetLocal EnableExtensions EnableDelayedExpansion
SET CHOICE=
ECHO. ARMBUS Versions
ECHO.
CALL :armbusVersions
ECHO.
SET /P CHOICE=Select A Version:
CALL :armbusVersions
ECHO.
ECHO. %armbusVersion% Selected
ECHO.
PAUSE
endlocal
exit /b 0
:armbusVersions
set /a amrbusOption = 0
for /d %%X in (
"C:\BusNet\Code\armbus\*"
) do (
SET /a armbusOption += 1
FOR /f "tokens=1-5 delims=\" %%a in ("%%X") do (
IF "%CHOICE%"=="" (
ECHO. !armbusOption! %%e
) ELSE (
ECHO. !armbusOption! %%e
IF [%CHOICE%]==[!armbusOption!] (SET armbusVersion=%%e & ECHO. SELECTED %%e)
)
)
)
GOTO :EOF
Re: List Directories as Menu Options
I see two possible problems:
typing error: amrbusOption -> armbusOption
use of space before the = sign could result in a new variable named 'armbusOption '
where you intend to update the value of the variable 'armbusOption'
OJB
Code: Select all
set /a amrbusOption = 0
typing error: amrbusOption -> armbusOption
use of space before the = sign could result in a new variable named 'armbusOption '
where you intend to update the value of the variable 'armbusOption'
OJB
-
- Posts: 4
- Joined: 05 Sep 2011 02:17
Re: List Directories as Menu Options
Guess i need to triple check my typing
Thanks though
Thanks though