How to delete a folder and all contents using a bat file in windows?

388,576

Solution 1

@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

Solution 2

  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\
Share:
388,576

Related videos on Youtube

learner
Author by

learner

Updated on July 19, 2022

Comments

  • learner
    learner almost 2 years

    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?

  • Hakikat41
    Hakikat41 over 3 years
    Can you please explain, why the @ flag befor RD ist needed and used? In the explanation there is only with rd.
  • Waihon Yew
    Waihon Yew over 3 years
    @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.
  • yu yang Jian
    yu yang Jian over 2 years
    to delete all subfolders in a folder, use * in for : for /d %G in ("D:\testfolder\*") do rd /s /q "%~G"