Choose a Directory Using Batch File

Microsoft Windows xp professional w/sp2
September 29, 2011 at 13:23:03
Specs: WIN7
How do I create a batch file that uses the DIR command to list all of the directories in a certain folder and then allow the user to choose which one to pick OR supply thier own patch/directory?



See More: Choose a Directory Using Batch File

Report •


#1
October 1, 2011 at 00:11:41
Here's a lazy method and probable not very efficient. Please test this.

Syntax is filename Directory\to\be\listed\

@echo off
setlocal enabledelayedexpansion
cls


dir /ad /b "%1">%temp%\tempdir.txt
set linecount=1

for /f "tokens=*" %%1 in (%temp%\tempdir.txt) do (
    echo !linecount! %%1>>%temp%\tempdir1.txt
    set /a linecount+=1
)

echo.&echo.
more %temp%\tempdir1.txt

echo.&echo.
set /p folder="Enter folder number to select or enter XXX to self-enter:  "
If /i "%folder%" equ "XXX" (goto selfenter)
set /a folder-=1

more +%folder% %temp%\tempdir.txt>%temp%\tempfile.txt

set /p directory=<%temp%\tempfile.txt
echo You have selected directory "%directory%"
exit /b

:selfenter
cls
echo.&echo.
set /p directory="Enter your selected path:  "
echo.&echo.
echo You have selected directory "%directory%"


del %temp%\temp*.*


Please come back & tell us if your problem is resolved.


Report •
Related Solutions


Ask Question