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. - Article authored by Kunal Chowdhury on .

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

Have a question? Or, a comment? Let's Discuss it below...

dhgate

Thank you for visiting our website!

We value your engagement and would love to hear your thoughts. Don't forget to leave a comment below to share your feedback, opinions, or questions.

We believe in fostering an interactive and inclusive community, and your comments play a crucial role in creating that environment.