Welcome to Dennis Lang's
Source Code and Performance Metrics

Linkedin: http://www.linkedin.com/pub/1/119/293

Updated: 13-Sep-2009

[ To Main Page ]

C# (Csharp):

C# Application to locate and delete files. Includes filter rules to locate Visual Studio temporary and build files.
Features include:
  • Saves and restores application settings to/from registry
  • All lists can be sorted and exported to CSV
  • Custom filter rules can be added
  • Can be registered as a Shell command to launch on choosen folder
  • Download executable xp32/net3.5: VStudioCleaner_v1.6-exe.zip
  • Download source code: VStudioCleaner_v1.6-src.zip

  • Introduction

    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 Leonarddo 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.

    1. All dialogs should allow resizing (and look good when size is increased)
    2. Avoid modal dialogs
    3. List/tables should support column sorting and multiple selection.
    4. Drag and Drop (thou this app has no specialize implementation)
    5. Export - make it easy to export information in a simple form (Text or csv)
    6. Remember configuration changes
    7. 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 four categories:
    1. Directory names, match directory and select all files and subdirectories
    2. File extensions, matches files
    3. Wildcard, matches directories and files
    4. Exclude files or directories

    1. 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.

    2. File extension must start with a decimal point. Example: .obj
    File extension filter only matches files.

    3. 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.
        Example:  Connect*.xml
        Example:  *foo*bar.*	          
    The wildcard filter is tested against 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 can contain one or more filters separated by semicolons. Example: Connect*.xml;.obj;obj\

    4. The exclude filter is evaluated last. Exclude filter starts with a minus sign. Example: *\bin\*;-*.exe

    The above example will match on the directory bin and all of its subdirectories and files. The exclude pattern will exclude all files with extension .exe from the matched files. NOTE: The exclude only works on File and Wildcard filters and not simple Directory name filters. The following will not work because the members of bin directory are not tested individually.

    Example:  bin\;-*.exe 

    Special Global Exclude Filter:

    If one or more exclude filters have their Filter name set to 'never', they are always evaluated to prevent files from being located. Remember to start the filter pattern with a minus sign.

    Filter Details Description
    never-exe -*.exe Don't remove executables
    never-cpp -*.cpp Don't remove source files cpp
    never-zed -*\Zed*\* Don't remove Zed graph directories

    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
    Filter names must be unique. Duplicate filters will be ignored next time you restart.


    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:

    1. How to launch RegEdit and get it to open on a specific registry entry
    2. How to force a listview to scroll to the left
    3. Registering VStudioCleaner to folder menu.
    4. Recursive pattern matcher
    5. Inline html help text

    RegEdit like most Windows applications save their 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;
              // Preset last place RegEdit visited to our registry section
              RegistryKey regEditKey = Microsoft.Win32.Registry.CurrentUser.CreateSubKey(@"Software\Microsoft\Windows\CurrentVersion\Applets\Regedit");
              regEditKey.SetValue("LastKey", @"My Computer\HKEY_CURRENT_USER\Software\" + appName);
              // Launch RegEdit which will default at the last place it was (our stuff).

    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 it to the left. Here is 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 register 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 stories 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.

            /// <summary>
            /// WildCompare supports simple '*' wildcard pattern.
            /// Returns true if pattern matches even if raw text has more characters.
            /// </summary>
            /// <returns> true for partial match</returns>
            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)
                            return true;
                            // Find match with char after '*'
                            while (rawOff < rawStr.Length &&
                                char.ToLower(rawStr[rawOff]) != char.ToLower(wildStr[wildOff + 1]))
                            if (rawOff < rawStr.Length &&
                                WildCompare(wildStr, wildOff + 1, rawStr, rawOff))
                                return true;
                        } while (rawOff < rawStr.Length);
                        if (rawOff >= rawStr.Length)
                            return (wildStr[wildOff + 1] == '*');
                        if (char.ToLower(rawStr[rawOff]) != char.ToLower(wildStr[wildOff]))
                            return false;
                        if (wildStr.Length == wildOff)
                            return true;
                return true;

    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
            public HelpDialog()
                byte[] byteArray = Encoding.ASCII.GetBytes(helpHtml);
                MemoryStream mr = new MemoryStream(byteArray);
                this.webBrowser.DocumentStream = mr;
            string helpHtml =
    "<html>" +
    "<body lang=EN-US>" +
    "" +
    "<p><span style='font-size:12.0pt'>Filters are patterns used to 
    select directories and files.</span>" +
    "<p>" +
    "<b><span style='font-size:12.0pt'>Patterns fall into four categories:</span></b>" +
    "" +
    "</body>" +

    Final Words

    This article is also publish on codeproject:

    I want to thank Leonardo Paneque for providing his CodeProject "Solution Cleaner". His home page is:


    A similar product is available from WiseCleaner:


    Revision History

  • Aug 23, 2009 v1.4
  • Aug 30, 2009 v1.5
  • Sep 13, 2009 v1.6
  • Top