Advertisement
Advertisement


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


Question

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?

2020/05/04
1
144
5/4/2020 4:03:43 PM

Accepted Answer

@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
2018/02/14
260
2/14/2018 5:53:11 PM

  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\
2016/12/16

del /s /q c:\where ever the file is*

This deletes all files in the folder and subfolders, but leaves empty subfolders


Source: https://stackoverflow.com/questions/7331056
Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Email: [email protected]