0

I am attempting to use a batch file to delete a folder, lets say it's called "D:\Pictures\1\Test". I want cmd to confirm that I want to delete the file before it deletes it using a single press of the "Y" key for yes, or the "N" key for no.

The code below prompts me to give a Y/N input and then closes the cmd window; however, it does not delete the file no matter what I press. If I simply type rmdir /s /q "D:\Pictures\1\Test", it deletes the folder and all containing files without issue, but does not give me a confirmation prompt. Here is my current code. What am I doing wrong?:

CHOICE /C YN /M "Are you sure?"
IF ERRORLEVEL 2 close
IF ERRORLEVEL 1 rmdir /s /q "D:\Pictures\1\Test"
dan1st
  • 12,568
  • 8
  • 34
  • 67
MrPlatipus
  • 13
  • 3

1 Answers1

2

There is no close command. Use exit /B instead.

You could simply remove the /Q switch from the rmdir command so it prompts you once whether or not to delete the given directory tree.

aschipfl
  • 33,626
  • 12
  • 54
  • 99
  • Neither of these options worked. Your first solution deleted the folder when I pressed both Y and N. The second one closed the program instantly without giving me time to press anything, and without deleting the folder. – MrPlatipus Sep 06 '15 at 05:23
  • 1
    I accidentally deleted `CHOICE /C YN /M "Are you sure?"`. It works perfectly now. Thanks for you help. – MrPlatipus Sep 07 '15 at 20:22