Page 1 of 1

Problem with ELSE.

Posted: 21 Jul 2020 17:30
by PAB
Good evening,

I have this code . . .

Code: Select all

set "Drive="
echo  Which drive would you like to check for ERRORS?
set /p "Drive=>Please enter the drive letter and press <Enter>: "

if not exist %volume% %Drive%:\ (
  echo  ERROR: The drive does NOT exist^^!
  echo ^>Press ANY key to return to the Options . . . & pause >nul
  cls & goto :Options
) else (
  if "%Drive%"=="C" (
  chkdsk %Drive%: /F
  echo  press ^<ENTER^> to return to the Options.
  echo  press ^<Y^> and ^<ENTER^>.
  goto :REBOOT_Choice
) else (
  chkdsk %Drive%: /F
  Please thoroughly check the results above
  echo ^>Press ANY key to return to the Options . . . & pause >nul
  cls & goto :Options
 )
)
What works OK:

[1] If I press <ENTER> instead of entering a drive letter it gives me the correct message . . .

Code: Select all

  echo  ERROR: The drive does NOT exist^^!
[2] If I enter an incorrect drive letter it gives me the correct message . . .

Code: Select all

  echo  ERROR: The drive does NOT exist^^!
[3] If I plugin a USB and it gets allocated drive letter G: for example, and I then run the code, it performs the chkdsk correctly and gives me the correct text after it has finished as shown in the code here . . .

Code: Select all

  Please thoroughly check the results above
  echo ^>Press ANY key to return to the Options . . . & pause >nul
  cls & goto :Options
What DOESN'T works OK:

If I enter C as the drive letter, it prompts me to either enter "Y" to perform chkdsk on the next reboot, or "N" to cancel the process. So far so good.

Code: Select all

  if "%Drive%"=="C"
Regardless of whether I enter "Y" or "N" I want it to show this . . .

Code: Select all

  echo  press ^<ENTER^> to return to the Options.
  echo  press ^<Y^> and ^<ENTER^>.
. . . and regardless of which I enter for it to . . .

Code: Select all

  goto :REBOOT_Choice
I have spent hours on this and it is almost there.

Any help will be greatly appreciated.

Thanks in advance.

Re: Problem with ELSE.

Posted: 22 Jul 2020 07:22
by PAB
I just couldn't seem to get it to do the WHOLE thing using If..Else...Else so I have come up with this . . .

Code: Select all

set "Drive="
echo  Which drive would you like to check for ERRORS?
set /p "Drive=>Please enter the drive letter and press <Enter>: "

if /i not exist %Drive%:\ goto :ERROR
if /i "%Drive%"=="C" goto :Drive_C
if /i not "%Drive%"=="C" goto :Drive_Other

:ERROR

echo  ERROR: The drive does NOT exist.
pause
cls & goto :Options

:Drive_C

chkdsk %Drive%: /F
echo  press ^<ENTER^> to return to the Options.
echo  press ^<Y^> and ^<ENTER^> to REBOOT.
goto :REBOOT_Choice

:Drive_Other

chkdsk %Drive%: /F
echo Please thoroughly check the results above
pause
cls & goto :Options
If anybody can get the above nested it would be great.

Thanks in advance.

Re: Problem with ELSE.

Posted: 23 Jul 2020 13:36
by IcarusLives
Perhaps your problem is this line?

Code: Select all

chkdsk %Drive%: /F
It should be

Code: Select all

chkdsk %Drive%:\ /F