How to ask for input
Posted: 07 Mar 2023 18:41
In this code I'm asking for a drive letter:
When I run it I get an error: & was unexpected at this time.
This is the output I get:
How can I fix it so I don't get the error.
If there is an easier way to check for a valid drive letter that would be great.
Thank you,
Code: Select all
:TryAgain
cls
::Windows 10 drive
Set Drive=
echo.
echo ===============================================================================
echo. Enter the Letter of the drive Windows is on: Example C
echo ===============================================================================
set /p Drive= ^> Enter Drive:
@Echo On
if [%Drive%]==[] echo.&echo Invalid User Input&echo.&pause&goto :TryAgain
if /I %Drive% leq C If /I %Drive% geq Z echo.&echo Invalid User Selection&echo.&pause&goto :TryAgain
if /I %Drive% geq C & if %Drive% leq Z goto :Next1
GoTo :TryAgain
:Next1
This is the output I get:
Code: Select all
===============================================================================
Enter the Letter of the drive Windows is on: Example C
===============================================================================
> Enter Drive:C
F:\SR>if [C] == [] echo. & echo Invalid User Input & echo. & pause & goto :TryAgain
F:\SR>if /I C LEQ C If /I C GEQ Z echo. & echo Invalid User Selection & echo. & pause & goto :TryAgain
& was unexpected at this time.
F:\SR>if /I C geq C & if C leq Z goto :Next1
If there is an easier way to check for a valid drive letter that would be great.
Thank you,