List Directories as Menu Options

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
techno-slut
Posts: 4
Joined: 05 Sep 2011 02:17

List Directories as Menu Options

#1 Post by techno-slut » 05 Sep 2011 02:31

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

Ed Dyreen
Expert
Posts: 1569
Joined: 16 May 2011 08:21
Location: Flanders(Belgium)
Contact:

Re: List Directories as Menu Options

#2 Post by Ed Dyreen » 05 Sep 2011 02:40

'

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

techno-slut
Posts: 4
Joined: 05 Sep 2011 02:17

Re: List Directories as Menu Options

#3 Post by techno-slut » 05 Sep 2011 03:33

Thanks for that Ed.

Works a treat :D

techno-slut
Posts: 4
Joined: 05 Sep 2011 02:17

Re: List Directories as Menu Options

#4 Post by techno-slut » 05 Sep 2011 05:13

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

OJBakker
Expert
Posts: 90
Joined: 12 Aug 2011 13:57

Re: List Directories as Menu Options

#5 Post by OJBakker » 05 Sep 2011 06:12

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

techno-slut
Posts: 4
Joined: 05 Sep 2011 02:17

Re: List Directories as Menu Options

#6 Post by techno-slut » 05 Sep 2011 06:17

:oops: Guess i need to triple check my typing

Thanks though :-)

Post Reply