How to batch clean up the Visual Studio solution folder? (bin, obj etc.)


Sometime the Visual Studio’s clean project command does not return as expected and maximum time people used to manually delete the bin, obj, Client Bin, Generated_Code directories to clean all the traces of previous build.

 

Here I will share a small batch code which will help you to clean up those directories by just a single click. Tune it up if you want to add few more directories in the list.

 

 

As a developer, you might be a victim of this issue where Visual Studio debugger stops working for your application and you have no other options than deleting the bin, obj folders. You might want to send your source code as an email attachment to someone but don’t want to include the compiled binaries or ReSharper cache. Also you might want to do a clean deployment of your code in web server where you want to make yourself confident that the previous compiled binary references don’t copied unknowingly.

 

If you are doing at least one of the above things and removing those named/unnamed folders & cache manually, this is the right post for you. Here I will share you a batch code, which will do the same for you automatically by just a single click.

 

Let’s see the algorithm of our implementation. We will traverse the directory and it’s sub directories to find out the listed folders, once found, will remove that directory & it’s contents silently. Here is what we want to achieve:

 

Algorithm to delete the directory

 

We will loop through a list to find out the specified folder name and remove them and their contents individually. To do this, open a notepad, copy the below code and save it as an batch file (generally with .bat or .cmd extension) which will execute on demand:

 

start for /d /r . %%d in (bin,obj, ClientBin,Generated_Code) do @if exist "%%d" rd /s /q "%%d"

 

Now put the file in the root directory and double click to execute the file. This will start a process to search for the folder names present in the list and permanently remove them with their contents silently. The default folder names that you need in most common cases are the bin and obj folders. If you are a Silverlight developer, you can add the ClientBin folder in the list as stated above. Also, if you are working with WCF RIA Services, the Generated_Code directory should be there in the list.

 

If you are using ReSharper or any other plugins which caches their temporary storage within the solution folder, you might want to change the above code to accommodate the name in the list.

 

I hope that the post will help you to resolve most of the issues regarding those folders which you can clean with just a single click and thus it will improve your productivity too. Drop a line below if that helps you and share such productive tips if you already know. Connect with me on Twitter and Facebook for technical discussions and updates.

 

Reference: An answer posted on superuser.com


If you have come this far, it means that you liked what you are reading. Why not reach little more and connect with me directly on Twitter , Facebook , Google+ and LinkedIn . I would love to hear your thoughts and opinions on my articles directly. Also, don't forget to share your views and/or feedback in the comment section below.

2 comments

  1. Nice article. By the way. Visual Smarter has a lot tools for Visual Studio. You may like it.

    Http://visualsmarter.blogspot.com/

    ReplyDelete
  2. Nice article. By the way. Visual Smarter has a lot tools for Visual Studio. You may like it.

    Http://visualsmarter.blogspot.com/

    ReplyDelete


 
© 2008-2016 Kunal-Chowdhury.com - Microsoft Technology Blog for developers and consumers | Designed by Kunal Chowdhury
Back to top