Use Powershell to delete all bin & obj folders

I sometimes need to remove all intermediate & resulting build files from a Visual Studio solution, either due to version conflicts or because of permissions issues. Powershell just made that job a whole lot easier.

Here’s the command to remove all obj & bin folders from a path (assuming you’re in the path now):

Get-ChildItem .\ -include bin,obj -Recurse | foreach ($_) { remove-item $_.fullname -Force -Recurse }

If you’re not in the correct folder just replace .\ with the full or relative path. You’ll still need to close down Visual Studio first, the -Force switch will override permission failures, but not process locks.

Note: this does a forced delete without prompting for confirmation, so you’d better be really sure you want it all gone. I highly recommend tacking a -WhatIf after the last -Recurse to do a dry run first to see what will be deleted, i.e.:

Get-ChildItem .\ -include bin,obj -Recurse | foreach ($_) { remove-item $_.fullname -Force -Recurse -WhatIf }

YMMV, but this has saved me much annoyance. If you know of any other handy scripts, drop them in a comment. Share the love!

4 thoughts on “Use Powershell to delete all bin & obj folders

  1. Pingback:

  2. Pingback: Through This Window

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>