Recursively find and delete a folder using a batch file
for /d /r "c:\" %%a in (temp\) do if exist "%%a" echo rmdir /s /q "%%a"
For each folder ( /d
) recursively ( /r
) in c:\
check if the folder temp
exists, and if it exists, delete it
the command to delete a directory is only echoed to the console. If the output is correct, remove the commandecho
source to share
Switch /S
on rd
means
/S Removes all directories and files in the specified directory
in addition to the directory itself. Used to remove a directory
tree.
This does not mean that it will search all directories that look for a name with the specified name and delete them.
In other words, if you run rd /S Test
from a folder C:\Temp
, it will remove C:\Temp\Test\*.*
, including all subdirectories (of any name) C:\Temp\Test
. It doesn't mean it will delete C:\Temp\AnotherDir\Test
, because it is not a subfolder C:\Temp\Test
.
source to share