Skip to main content

Command line del c:\mydir\*.* - delete subfolders also [Resolved]

I have a script that runs the command:

del c:\mydir\*.*

Is there a command line switch I can use that will also delete all subfolders in that directory? Thanks!


Question Credit: Mike Cole
Question Reference
Asked July 11, 2018
Posted Under: Network
30 views
6 Answers

Instead of complex FOR...LOOPS etc. I would just use:

c:
cd\mydir
del /q *.* /s 

... but an even faster method is:

rd /q /s c:\mydir

as RD is "remove directory" just as the old DELTREE


credit: BerggreenDK
Answered July 11, 2018

Yes, rmdir.

(hint: rmdir /?)

Edit: You probably want to keep the folder. Try this out in a batch file:

@echo off
rmdir C:\mydir /S
mkdir C:\mydir

credit: pauska
Answered July 11, 2018

The shortest and simplest way:

CD "%temp%\OrYourPath\" && RD /q /s .

This preserves the parent folder, which may have ACLs that you want to keep. If any of the contents are in use, you will get errors. If you want to silence and ignore those, add a 2>nul at the end.

If you want to remain in the current directory, or have a UNC path, use PUSHD + RD + POPD instead of CD + RD.


credit: Amit Naidu
Answered July 11, 2018
Your Answer
D:\Adnan\Candoerz\CandoProject\vQA