Reputation: 153
I have some code to display options to allow the user to choose from. Currently the code displays the entire path. Is there anyway to just display the folders at the end of the path?
Here is my code so far
:incorrect1
@echo 3. Select a folder from the list below
echo[
setlocal enabledelayedexpansion
set Index=1
for /d %%D in ("C:\Projects\Google\Automation\TestResults\*") do (
set "Subfolders[!Index!]=%%D"
set /a Index+=1
)
set /a UBound=Index-1
setlocal enabledelayedexpansion
for /l %%i in (1,1,%UBound%) do echo %%i. !Subfolders[%%i]!
:choiceloop
set /p Choice=Your choice:
if "%Choice%"=="" goto chioceloop
if %Choice% LSS 1 goto choiceloop
if %Choice% GTR %UBound% goto choiceloop
set Subfolder=!Subfolders[%Choice%]!
echo[
set /P c=Are you happy with your selection[Y/N]?
if /I "%c%" EQU "N" goto :incorrect1
if /I "%c%" EQU "Y" goto :happy so move on1
:happy so move on1
Upvotes: 1
Views: 46
Reputation: 130819
Simply use %%~nxD
to get the name and extension of the file, without drive or path information.
set "Subfolders[!Index!]=%%~nxD"
There are a number of modifiers that can be applied to FOR variables that are analogous to modifiers that can be applied to parameters like %1
, etc.
You can read about it from the command line by executing help for
or for /?
.
Upvotes: 1