I'm currently working on some batch file that will be deleting all files from selected usb drive. The code works, but i wanted to add second choice to be sure if user is certain that he choose correct drive or so and the second choice is not responding. No matter which option i'll choose it'll somehow delete all files from this point.
I'm new to batch and to programming also
Here's a code:
@echo off
choice /c YN /t 15 /d n /m "Do you want to delete all files from USB drive? Y-yes, N-no"
setlocal enabledelayedexpansion
Set "USB="
if errorlevel == 1 goto ONE
if errorlevel == 2 goto TWO
if errorlevel == 255 goto ERROR
:ONE
for /f "tokens=1-5" %%a in (
'wmic logicaldisk list brief'
) do if %%b Equ 2 if %%d gtr 0 Set USB=!USB! %%a
Echo:Found drive's:%USB%
set /p Drive=Choose drive:
if "%Drive%"=="" goto :ERROR
if not exist %drive%:\ goto :ERROR
if %drive% EQU C goto ERROR
if %drive% EQU D goto ERROR
cd /D %Drive%:
tree
:CHOICE
choice /c YN /t 15 /d N /m "Are you sure you want to delete all files? Y-yes, N-no"
if errorlevel == 1 goto DELETE
if errorlevel == 2 goto TWO
goto END
:TWO
echo "Program was cancelled"
goto END
:DELETE
del * /S /F /Q
rmdir /S /Q %Drive%:
echo "Files are deleted"
goto END
:ERROR
echo "There was an error"
goto end
:END
echo "Done"
pause