you can avoid the recursion problem not using recursion, that means replace call by goto and use a variable instead a parameter. Also, you have a mistake using normal expansion of variable inside the foor loop, because that expansion is done before the block is executed, then try to get the actual value inside the block is imposible using normal expansion, because you are not expanding that variable value in that point (cmd expand it before execute the block), for solve it use delayed expansion.
check this if works for you:
Code: Select all
@echo off
SETLOCAL ENABLEDELAYEDEXPANSION
:INI
echo Virtual Drives:
echo ------------------------------------------
for /f "tokens=1,3,* delims=: " %%a in ('subst') do (
echo %%a:\ ......... %%c
)
echo ------------------------------------------
:INPUT
set "toRelease="
set /p "toRelease=release"
if not defined toRelease GOTO :EOF
set "toRelease=!toRelease:~0,1!"
:RELEASE
subst !toRelease!: /D
for /f "tokens=1,3,* delims=: " %%a in ('subst') do (
set "FolderPath=%%c"
set "DriveLetter=%%a"
if "!toRelease!" == "!FolderPath:~0,1!" (
set "toRelease=!DriveLetter!"
GOTO :RELEASE
)
)
using it maybe you not get the subst message that the volumen is not found, because you are really get the value of DriveLetter variable.
Anyways if you need check if the volumen is mounted (for example the user input is a letter of volumen not mounted), I remember that the way is using vol command like this:
using z as example:
Code: Select all
vol z: >nul 2>&1
if errorlevel 1 (set "exist=0") else (set "exist=1")