15

How to delete a folder in a batch file forcely ?

(Note- C:\Anything is a folder)

My code is:

@echo off
del C:\Anything
pause

But it's always asking-

Do you want to delete "C:\Anything" Y/N ?

I want that C:\Anything should delete with askimg for permision to do that !

Please help to optimize my problem !!!

MC ND
  • 69,615
  • 8
  • 84
  • 126
Ekagra Srivastava
  • 171
  • 1
  • 1
  • 5
  • 1
    Did you try `del /f /q C:\Anything`? You should look at `del /?` for options. – lurker Sep 16 '14 at 15:08
  • Possible duplicate of [How to delete a folder with all contents using a bat file in windows?](http://stackoverflow.com/questions/7331056/how-to-delete-a-folder-with-all-contents-using-a-bat-file-in-windows) – Yerko Palma Oct 09 '15 at 17:57

2 Answers2

38

Use the rd command to delete folders:

rd /s /q "C:\My Folder\"

/s: Deletes all files and folder from selected path.

/q: Suppress any message.

The official docs are here.

Oliver
  • 9,239
  • 9
  • 69
  • 100
Honguito98
  • 664
  • 8
  • 13
  • 3
    Considering that this is a site for questions and answers, and I found this result because it was specifically what I was looking for, don't you think it's kind of silly to tell people to read the documentation here? – Slothario Aug 01 '16 at 21:02
  • 1
    what if I see "The process cannot access the file because it is being used by another process." and don't know what process is holding that? – Raj Jun 11 '18 at 17:50
  • does not work with some occiped files, which can be delete via 'Delete' key – iperov Oct 23 '21 at 15:01
5
set backupDir="D:\db_backup"

rmdir /s /q %backupDir%

here /q will eliminate that confirmation question.

street hawk
  • 565
  • 7
  • 12