1

am tring to make a selectable list by numbers for the folders only,

Example:

1 - FolderA
2 - FolderB
3 - FolderD

Please enter your folder number:
You have selected folder number 2
Your folder name Is: FolderB

I tried a lot to use "dir /b" but I fail...!

I found this example but can't get the user selection...!

REM Ref: https://stackoverflow.com/questions/17057321/batch-file-to-list-folders-and-allow-user-selection
@echo off
cls
setlocal EnableDelayedExpansion

set /a count=0

for /d %%d in (*) do (
    set /a count+=1
    @echo !count!. %%d 
)
setlocal DisableDelayedExpansion

set /P selection="select folder number:"
echo %selection%
echo %count%
pause

%selection% showing the entred number, not the folder name...! & %count% showing the number of the all folders In current path.

1 Answers1

1

Because %selection% is assigned to the number you type at the prompt, and not the actual folder name which had metavariable of %%d and it was never assigned to a variable.

@echo off
setlocal EnableDelayedExpansion

set /a count=0

for /d %%d in (*) do (
    set /a count+=1
    @echo !count!. %%d
    set "fold!count!=%%~d"
)

set /P selection="select folder number:"
echo !fold%selection%!
echo %count%
pause
Gerhard
  • 22,678
  • 7
  • 27
  • 43