Windows – Delete a sub folder with specific name from all sub folders

command-line-interfacewindows

I know how to delete a single sub folder or multiple ones by mask:

rmdir /s /q C:\Somedir\DirToDelete

or

rmdir /s /q C:\Somedir\DirsToDelete*

But I want to delete all sub folders, say, with name DeleteMe, from all sub folders within C:\Somedir.

Ideas?

Best Answer

First you want to list all the directories you want to remove. Then use that to delete them all. Here's a quick and dirty example using what you put in there.

for /f "usebackq" %%a in (`"dir C:\Somedir /ad/b/s DirsToDelete"`) do rmdir "%%a"

Please test this out before you kick it off for your environment. I usually would replace the rmdir with echo to make sure it works.