Batch file. Delete all files and folders in a directory

user69514 picture user69514 · Jul 26, 2011 · Viewed 418.8k times · Source

I want to have a batch file that will delete all the folders and files in my cache folder for my wireless toolkit.

Currently I have the following:

cd "C:\Users\tbrollo\j2mewtk\2.5.2\appdb\RMS"
del *.db

This will delete all .db files in my RMS directory, however I want to delete every single thing from this directory. How can I do this?

Answer

GregM picture GregM · May 9, 2013

Use:

  • Create a batch file

  • Copy the below text into the batch file

    set folder="C:\test"
    cd /d %folder%
    for /F "delims=" %%i in ('dir /b') do (rmdir "%%i" /s/q || del "%%i" /s/q)
    

It will delete all files and folders.