On 23.06.2016 11:29, Harry Potter wrote:
> I'm sorry. :( The file, when run, displays all the directories in a given directory,
> asks the user to type in the name of the directory to copy, then copies the directory
> to the directory specified in the argument. I want the user to *select* the directory
> rather than *type in* the directory.
Phil gave you an example using "set /p", here is one using "choice":
This batch will list all subdirectories in the current directory
(max 26, but you can add A-Z and 1-9 if you need more). By pressing a
key a-z you can select one of them.
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
@echo off
cls
setlocal enabledelayedexpansion
set n=0
for %%i in (a b c d e f g h i j k l m n o p q r s t u v w x y z) do (
set /a n += 1
set abc[!n!]=%%i)
set m=0
for /f "tokens=*" %%i in ('dir /ad /b ') do (
if !m! geq %n% goto :max
set /a m += 1
set dir[!m!]=%%i
call echo [%%abc[!m!]%%] %%i)
:max
set s=
for /l %%i in (1,1,%m%) do set s=!s!!abc[%%i]!
set /a m += 1
choice /c %s%0 /cs /n /m "Which one [press 0 to abort] :"
if errorlevel %m% echo aborted & goto :eof
call set d=%%dir[%errorlevel%]%%
echo You selected: %d%