214

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*.* 

How can I fix it?

2
  • Re "it is not working": Can you be more specific? For example, what happens? Or doesn't happen? Commented Jul 4 at 0:06
  • OK, the OP has left the building: "Last seen more than 13 years ago" Commented Jul 4 at 0:06

2 Answers 2

379

Use:

@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 
Sign up to request clarification or add additional context in comments.

2 Comments

Can you please explain, why the @ flag befor RD ist needed and used? In the explanation there is only with rd.
@Hakikat41 it's the symbol for reducing verbosity in batch files. 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.
65
  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\

1 Comment

to delete all subfolders in a folder, use * in for : for /d %G in ("D:\testfolder\*") do rd /s /q "%~G"

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.