175

I want to delete a folder with all files and subfolders using a bat file.

I have tried the following, but it is not working:

@DEL D:\PHP_Projects\testproject\Release\testfolder*.*

Can anybody help?

iliketocode
  • 6,978
  • 5
  • 46
  • 60
learner
  • 2,419
  • 3
  • 20
  • 22

2 Answers2

316
@RD /S /Q "D:\PHP_Projects\testproject\Release\testfolder"

Explanation:

Removes (deletes) a directory.

RMDIR [/S] [/Q] [drive:]path RD [/S] [/Q] [drive:]path

/S      Removes all directories and files in the specified directory
        in addition to the directory itself.  Used to remove a directory
        tree.

/Q      Quiet mode, do not ask if ok to remove a directory tree with /S
Cristian Ciupitu
  • 19,240
  • 7
  • 48
  • 73
Jon
  • 413,451
  • 75
  • 717
  • 787
  • 6
    Can you please explain, why the @ flag befor RD ist needed and used? In the explanation there is only with rd. – Hakikat41 Oct 22 '20 at 08:40
  • 6
    @Hakikat41 it's the symbol for [reducing verbosity in batch files](https://stackoverflow.com/q/21074863/50079). It doesn't affect the operation of the command itself, and doesn't do anything outside of batch files. Looking at the question, I imagine I put it there because the question itself has the `DEL` command with it included. – Jon Oct 22 '20 at 09:02
48
  1. del /s /q c:\where ever the file is\*
  2. rmdir /s /q c:\where ever the file is\
  3. mkdir c:\where ever the file is\
mtb
  • 1,308
  • 15
  • 31
user3319853
  • 507
  • 4
  • 2