Ok, figured out that it's hard to recursively search subfolders and delete those folders matching a pattern using a batch file and cmd
. Luckily, PowerShell (which is installed on Windows 7 by default, IIRC) can do it (kudos):
get-childitem C:\Projects\* -include TestResults -recurse | remove-item -recurse -force
That was based off of example 4 of the Remove-Item
help entry. It searches the path, recursively, for anything (file or folder) named "TestResults" (could put a wildcard in there if wanted) and pipes the results to the Remove-Item
command, which deletes them. To test it out, just remove the pipe to Remove-Item
.
How do we remove more than just one folder per statement? Input the list of folders in PowerShell's array syntax:
get-childitem C:\Projects\* -include bin,obj,TestResults -recurse | remove-item -recurse -force
You can run this from the command prompt or similar like so (reference)
powershell.exe -noexit get-childitem C:\Projects\* -include bin,obj,TestResults -recurse | remove-item -recurse
Obvious Disclaimer
Don't use this method if you keep necessary files inside folders or files named bin
, obj
, etc.