Cleaning up Visual Studio C++ projects

After manually cleaning up Visual Studio C++ solutions for a long time, finally I had enough when I was trying to clean a Cocos2d-x project with its nested hierarchy of projects.. each with its own bin/debug/arm folders. So I started searching for a solution using powershell. Then I found this awesome blog post by Ricky.

Unfortunately, Ricky left out one particularly egregious file, the sdf file which contains the parsed symbols for C++ projects and helps with the Visual Studio intellisense. This file easily grows to be a few hundred megs so definitely warrants removal. So, I added a teensy bit to Ricky’s script and my life is now a lot easier.

Get-ChildItem .\ -include ARM,bin,obj,bld,Backup,_UpgradeReport_Files,Debug,Release,ipch -Recurse | foreach ($_) { remove-item $_.fullname -Force -Recurse };Get-ChildItem -Path *.sdf -Recurse -Force |  foreach ($_) { remove-item $_.fullname -Force -Recurse }

In case you are curious, let’s deconstruct the above command line:

Get-ChildItem .\ -include ARM,bin,obj,bld,Backup,_UpgradeReport_Files,Debug,Release,ipch -Recurse

The above recursively finds all folders under the current folder that match the names ARM, bin, obj etc.

foreach ($_) { remove-item $_.fullname -Force -Recurse }

This line simply gets whatever gets passed to it via the pipe command and simply removes everything under it recursively.

It is not too hard to decipher, that all I did was to add one more command to Ricky’s script which simply finds all files that have extension sdf and removes them using the above command.


Leave a comment

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