Delete a sub folder with specific name from all sub folders?

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.


Another way is (only PowerShell)

 Remove-Item -path e:\path\*\path\*\* -Filter *DeleteMe* -WhatIf

Remove all DeleteMe dirs recursive in last "asterisk" path.

-WhatIf = only show which dirs will remove, no do it - nice for check before destroy other data:)

UPDATE 1 After some labor... this update is better... line before can delete only empty folders. This can delete folder with content:

get-childitem -path E:\path\*\path\*\* -recurse -filter *DeleteMe* | remove-item -whatif -force -recurse