Page 1 of 1

List Directories as Menu Options

Posted: 05 Sep 2011 02:31
by techno-slut
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

Re: List Directories as Menu Options

Posted: 05 Sep 2011 02:40
by Ed Dyreen
'

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

Re: List Directories as Menu Options

Posted: 05 Sep 2011 03:33
by techno-slut
Thanks for that Ed.

Works a treat :D

Re: List Directories as Menu Options

Posted: 05 Sep 2011 05:13
by techno-slut
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

Re: List Directories as Menu Options

Posted: 05 Sep 2011 06:12
by OJBakker
I see two possible problems:

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

Re: List Directories as Menu Options

Posted: 05 Sep 2011 06:17
by techno-slut
:oops: Guess i need to triple check my typing

Thanks though :-)