Search code examples
cmdcommand-promptdel

Remove only files and sub folders from a directory through command prompt


I have a folder named Test in C:\Test path. There are multiple files and folders in this Test folder. Now I want to remove all the contents with in the Test Folder and not delete the Test folder itself.

I have been trying these commands, but it only deletes the files and not folders.

del C:\Test\* 
del C:\Test\*.*

I want a single command to delete both files and sub folders from Test.


Solution

  • This is the command which has to be used.

    CD "C:/Test" && FOR /D %i IN ("*") DO RD /S /Q "%i" && DEL /Q *.*