193

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?

John Smith
  • 7,243
  • 6
  • 49
  • 61
learner
  • 2,609
  • 4
  • 22
  • 23

2 Answers2

349
@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
  • 20,270
  • 7
  • 50
  • 76
Jon
  • 428,835
  • 81
  • 738
  • 806
  • 9
    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
  • 8
    @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
58
  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,350
  • 16
  • 32
user3319853
  • 607
  • 5
  • 2