If you publish or share your software, or are just a neat freak and like to keep your disk clean, you will appreciate this utility to remove superfluous files. Visual Studio generates extra files which can be safely deleted because they are either automatically generated or are produced when you build your solution. This utility is based off of the CodeProject "VS.NET Solution Cleaner" by Leonardo Paneque and borrows some behavior from "Wise Cleaner". VstudioCleaner is basically a file and directory search engine which presents the results for deletion. The search 'filters' can be changed. Groups of filter settings can be associated with 'bookmarks' for quick recall. My personal hang ups with other applications are the inverse of the following features I offer and guidelines I try to adhere to when creating software.
- All dialogs should allow resizing (and look good when size is increased)
- Avoid modal dialogs
- List/tables should support column sorting and multiple selection
- Drag and Drop (though this app has no specialized implementation)
- Export - make it easy to export information in a simple form (Text or CSV)
- Remember configuration changes
- Ideally the program should be a single executable
This program is more than just a Visual Studio cleaner because the filters are expandable. You can create your own set of filters and bind them to a bookmark for easy recall. You can use it to cleanup your browser droppings.
How To Use
To use VStudioCleaner, you need to set the search Path to one or more directories and select one or more filters. The search "path" can be set by either typing in the path, cut & paste a path or using the Path... button to browse and select a path. If you need to specify multiple paths, you cannot use the Path... button because it does not append, it only knows how to set the search path. Multiple directory (folder) paths are specified by separating them by semicolon, as in:
You set your filters by either 'checking' or 'unchecking' the built-in filters or by adding your own filters. Once the search "Path" and "Filters" are set, press the "Locate" button to build up a list of files and directories. The resulting list will appear in its own dialog. You can sort the various columns (why, directory, file, extension, size) and right-click to remove files from the list. The right-click remove action only removes the names from the list, it does not remove anything from your computer. Once you have your list of files pruned down to those you want to delete from your computer, you can press the "delete" button.
Warning - The delete action is permanent. The files will NOT appear in the Recycle Bin.
Filters are patterns used to select directories and files. Filters fall into three categories:
- Directory names, match directory and select all files and subdirectories
- File extensions, matches files
- Wildcard, matches directories and files
Directory filters must end in a back slash. Example: debug\
Directory filters only match on directory names and cause the directory and all of its subdirectories and files to be selected.
File extension filters must start with a decimal point. Example: .obj File extension filter only matches files.
Wildcard filter is a collection of characters which includes one or more wildcard characters "*". Each wildcard can appear multiple times.
* matches zero or more characters.
The wildcard filter is compared with the full file or directory path, so it is common for all wildcard patterns to start with * to match any prefix of disk drive letters and directories.
Pattern Test Against Results
-------------------- ---------------------------------- ----------
foo* foobarcar match
foo* carbarfoo no match
*foo carbarfoo match
*foo c:\alpha\beta\foo match
*foo\bin\* foo\junk no match
*foo\bin\* foo\bin\ match
*foo\bin\* c:\alpha\foo\bin\ match
*\bin\*.obj c:\foo\bar\bin\car.obj match
*\bin\*.o* c:\foo\bar\bin\car.old match
*\bin\*.o* d:\bin\junk.obj match
A filter rule can contain one or more filters separated by semicolons. Example: Connect*.xml;.obj;obj\
Use "Add" and "Delete" buttons to manage your collection of filter rules. Double click on a row to change its value. Right click if you want to Export the filter rules as CSV.
Use the bookmarks to memorize a set of filter rule checkmark states and Path setting. Use the bookmark Add button to add a new bookmark to remember the current settings. Double Click on a bookmark to activate its settings. Press the "Set" button to refresh the current state of a selected bookmark to the current list of active filter rules and Path.
- Control-A to select entire List
- Space to toggle check boxes
- Delete key to delete selected items or item under mouse
- Up/Down to navigate up/down list and select row
No undo to restore items removed from a list or any undo to restored DELETED files or directories. Deleted files and directories will not appear in your recycle bin so you have no way to undo your deletions.
Sample screen of File and Directory List Located using default filters:
Points of Interest
While writing this application, I learned the following:
- How to launch RegEdit and get it to open on a specific registry entry
- How to force a listview to scroll to the left
- Registering VStudioCleaner to folder menu
- Recursive pattern matcher
- Inline HTML help viewer
RegEdit, like most Windows applications, saves session settings in the registry. Before you launch RegEdit, you simply set the value of LastKey in section Software\Microsoft\Windows\CurrentVersion\Applets\Regedit to the registry path of your entries.
private void openRegistry_Click(object sender, EventArgs e)
string appName = Application.ProductName;
RegistryKey regEditKey = Microsoft.Win32.Registry.CurrentUser.CreateSubKey
("LastKey", @"My Computer\HKEY_CURRENT_USER\Software\" + appName);
The second trick "to scroll listview left" was required when a user is editing a row in a
ListView. Depending on the size of the UI, it is possible that part of the row is not visible. Before a column is edited, I wanted it to be in view so I had to scroll the listview to the left. Here is the code I use to send keys to the UI in focus.
for (int i = 0; i < shift; i++)
VStudioCleaner can be registered to appear in the Shell Folder popup menu.
Example of Option menu showing register selection:
Once VstudioCleaner is registered to the shell folders, you can right click on a folder and easily launch VStudioCleaner on that folder. The folder path will appear as its default search path. Below is an image of the menu which appears when you right-click on a folder. This trick is thanks to "Leonardo Paneque" and his CodeProject "Solution Cleaner". Using trick #1 above, VStudioCleaner has menu picks to open the Windows Registry in both the section where VStudioCleaner stores its session info as well as the Shell Folder menu settings.
Sample of menu when you right-click a folder, showing VStudioCleaner:
This program also includes a simple wildcard pattern matching engine. It only supports a single specialized wildcard '*' but the wildcard can appear multiple times in the pattern.
private bool WildCompare(string wildStr, int wildOff, string rawStr, int rawOff)
while (wildOff != wildStr.Length)
if (rawOff == rawStr.Length)
return (wildStr[wildOff] == '*');
if (wildStr[wildOff] == '*')
if (wildOff + 1 == wildStr.Length)
while (rawOff < rawStr.Length &&
char.ToLower(wildStr[wildOff + 1]))
if (rawOff < rawStr.Length &&
WildCompare(wildStr, wildOff + 1, rawStr, rawOff))
} while (rawOff < rawStr.Length);
if (rawOff >= rawStr.Length)
return (wildStr[wildOff + 1] == '*');
if (char.ToLower(rawStr[rawOff]) != char.ToLower(wildStr[wildOff]))
if (wildStr.Length == wildOff)
Because the pattern matching is complex I added a popup help dialog, launched by pressing the "?" button. The original version used a
RichTextBox. I found it painful to setup font size and colorization, so I switched in version v1.5 to HTML. I wanted to keep vstudtiocleaner a single program and did not want a CHM or HTML help file. Since my help text is reasonably short, I just embedded it in the program. Here is part of the code in helpdialog.cs.
public partial class HelpDialog : Form
byte byteArray = Encoding.ASCII.GetBytes(helpHtml);
MemoryStream mr = new MemoryStream(byteArray);
this.webBrowser.DocumentStream = mr;
string helpHtml =
"<body lang=EN-US>" +
"<p><span style='font-size:12.0pt'>Filters are patterns used to
select directories and files.</span>" +
"<b><span style='font-size:12.0pt'>Patterns fall into four categories:</span></b>" +
Additional source code and information is available on my home website:
I want to thank Leonardo Paneque for providing his CodeProject "Solution Cleaner". His home page is:
- Aug 23, 2009 v1.4
- Moved error
messageBox from background files thread to main thread. Thanks to Ashutosh Bhawasinka.
- Aug 30, 2009 v.5
- Fixed sorting size column when search limit reached
- Added inverse selection and delete Now menu choices
- Sep 13, 2009 v1.6
- Added support for multiple 'never' filter entries. 'Never' only needs to be a prefix to a filter name
- Added warning message box to NOW delete menu pick
- Another fix to sorting columns with missing values
- Updated help message
- Fixed filescan dialog optional filter box to keep selection active when you click on the list
- Dec 17, 2011 v1.8
- Added foreground and background colors to filters
- Remember last bookmark and reset on startup. Show bookmark in title bar
- Fixed registry settings and viewing on Windows 7
- Fixed multiple path list, will color directory red if directory is invalid
- Fixed some delete error status messages
- Fixed links in About box, fixed about box to resize
I love C/C++ for its speed and power and C#/Visual Studio for quick application development.
Unix/Linux is my favorite OS
Android Studio is the best IDE I have used.