Click here to Skip to main content
11,715,022 members (73,647 online)
Click here to Skip to main content
Articles » Languages » C# » Utilities » Downloads
Add your own
alternative version

Visual Studio Cleaner and More

, 18 Dec 2011 CPOL 31.5K 1.7K 56
Delete junk files from Visual Studio solution/project by selecting files using search patterns
vstudiocleaner-exe.zip
VStudioCleaner.exe
vstudiocleaner-v1.8-src.zip
vstudiocleaner-v1.8
blackBubbles.jpg
dennis-lang-web.html.url
Desktop.ini
doc-web
logo.png
vsCleaner.png
vstudioCleaner-files.png
vstudioCleaner-main.png
vstudioCleaner1.png
vstudioCleaner2.png
vstudioCleaner3.png
vstudioCleaner4.png
vstudiocleanerA.gif
Thumbs.db
vBar.png
VStudioCleaner
Properties
Resources
help.rtf
VstudioCleaner.ico
VstudioCleaner.ico
VstudioCleaner.png
vstudiocleaner_v1.3.zip
vstudiocleaner_v1.3
blackBubbles.jpg
vBar.png
VStudioCleaner
Properties
VstudioCleaner.ico
VstudioCleaner.ico
VstudioCleaner.png
vstudiocleaner_v1.4-exe.zip
VStudioCleaner.exe
vstudiocleaner_v1.4-src.zip
vstudiocleaner_v1.4
blackBubbles.jpg
vBar.png
VStudioCleaner
Properties
VstudioCleaner.ico
VstudioCleaner.ico
VstudioCleaner.png
vstudiocleaner_v1.5-exe.zip
VStudioCleaner.exe
vstudiocleaner_v1.5-src.zip
vstudiocleaner_v1.5
blackBubbles.jpg
Desktop.ini
Thumbs.db
vBar.png
VStudioCleaner
Properties
VstudioCleaner.ico
VstudioCleaner.ico
VstudioCleaner.png
help.rtf
Resources
help.rtf
<html>
<style>
BODY {
    color: #ffffff;
}
.indent {
    padding-left: 50pt;
    padding-right: 50pt;
    font-size: 110%;
}
.indentBorder {
    padding-left: 50pt;
    padding-right: 50pt;
    font-size: 110%;
    border-color: grey;
    border-width: 1;
    border-style: solid;
}


.LIw { color:yellow; }
.LIa { color:white; }
LI { color:Yellow; }
H2 { color:Orange; }
PRE { background-color:gray; margin:30px; border:1px solid blue; }

</style>

<title>Dennis Lang Source code and performance metrics</title>
<BODY bgcolor="#404040" vlink="#f0fff0" hlink="#80ff80" alink="#80ff00" link=#ffffff>

<table>
<tr>
  <td>
  <img alt="logo" src="logo.png">
  

  <td> 
    <span style="font-size:x-large; font-weight:bold;";> Welcome to Dennis Lang's</span> <br>
    <span style="font-size:large; color:#ff0000;"> Source Code and Performance Metrics </span><br>
    <p>
    lang.dennis<b>@</b>comcast.net <br>Linkedin: http://www.linkedin.com/pub/1/119/293 <p>
    Updated: 17-Dec-2011
    <p>
    <a href="http://home.comcast.net/~lang.dennis/index.html" color=blue > [ To Main Page ] </a>

    <!-- Use of this code assumes agreement with the Google Custom Search Terms of Service. -->
    <!-- The terms of service are available at /coop/docs/cse/tos.html -->
    <form name="cse" id="searchbox" action="http://www.google.com/cse">
      <input type="hidden" name="cref" value="" />
      <input type="hidden" name="ie" value="utf-8" />
      <input type="hidden" name="hl" value="" />
      <input type="hidden" name="sitesearch" value="home.comcast.net/~lang.dennis/" />
      <input name="q" type="text" size="40" />
      <input type="submit" name="sa" value="Search" />
    </form>
    <script type="text/javascript" src="http://www.google.com/cse/tools/onthefly?form=searchbox&lang="></script>
</table>

<a name=top>
<p>
<hr>
<p>
<a name=vstudiocleaner>
<a name=cleaner>
<h2>C# - Visual Studio Cleaner and More  - v1.8 (Dec 2011)</h2>


<table>
 <tr>
  <td> 
    <img alt="vstudiocleaner" src="vstudiocleanerA.gif">
  <td>
  <h3>Download:</h3>
  <li>Download executable xp32/net3.5: <a href=vstudiocleaner.exe> <b> VStudioCleaner.exe  </b></a>
  <li>Download source code: <a href=vstudiocleaner-v1.8-src.zip> <b> VStudioCleaner-v1.8-src.zip  </b></a>
</table>
<h2>Introduction</h2>

<p>
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  <b>"VS.NET Solution Cleaner"</b> by  Leonarddo Paneque and borrows some behavior from <b>"Wise Cleaner"</b>.
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.
<p>
<blockquote>
  <li> All dialogs should allow resizing (and look good when size is increased) 
  <li> Avoid modal dialogs                                                      
  <li> List/tables should support column sorting and multiple selection.        
  <li> Drag and Drop (thou this app has no specialize implementation)           
  <li> Export - make it easy to export information in a simple form (Text or csv)
  <li> Remember configuration changes 
  <li> Ideally the program should be a single executable
</blockquote>

<p>
  <p><img alt="mainscreen" src="vstudioCleaner1.png"> 


 
<p>
This program is <b>more</b> 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.
 

C# Application to locate and delete files. Includes filter rules to locate Visual Studio temporary and build files.

<h3>Features include:</h3>
  <blockquote>
    <li> Saves and restores application settings to/from registry
    <li> All lists can be sorted and exported to CSV
    <li> Custom filter rules can be added
    <li> Can be registered as a Shell command to launch on choosen folder
  </blockquote>



 
<h2>How To Use</h2>
To use VStudioCleaner you need to set the search Path to one or more directories and select one or more filters.
The search <b>"path"</b> can be set by either typing in the path, cut&paste a path or using the <b>Path...</b>  button to browse and select a path.
If you need to specify multiple paths, you cannot use the <b>Path...</b> 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:
<pre>		
c:\dir1;c:\dir2\subdir1;d;\dir3\subdir2;e:\
</pre>
You set your filters by either 'checking' or 'unchecking' the built-in filters or by adding your own filters.
Once the search <b>"Path"</b> and <b>"Filters"</b> are set, press the <b>"Locate"</b> 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 <b>"delete"</b> button.  
<p>
<b><font color=Red>Warning</font></b> - The delete action is permanent.  The files will NOT appear in the Recycle Bin.

<h2>Filters</h2>
Filters are patterns used to select directories and files.  Filters fall into four categories:
<blockquote>

1.	Directory names, match directory and select all files and subdirectories
<br>2.	File extensions, matches files
<br>3.	Wildcard, matches directories and files
<br>4.    Exclude files or directories

</blockquote>

<p>
<b>1.</b> Directory filters must end in a back slash. Example:  <b> debug\ </b>
<br>
Directory filters only match on directory names and cause the directory and all of its subdirectories and files to be selected.
<p>
<b>2.</b> File extension must start with a decimal point. Example: <b> .obj </b>  
<br>File extension filter only matches files.

<p>
<b>3.</b> Wildcard filter is a collection of characters which includes one or more wildcard characters "*".  Each wildcard can appear multiple times.
<pre>
    *   matches zero or more characters.
    Example:  Connect*.xml
    Example:  *foo*bar.*	          
</pre>
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.

<p>
<pre>
    Example
    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
</pre>
A filter can contain one or more filters separated by semicolons.
Example:   <b> Connect*.xml;.obj;obj\  </b>
<p>
<b>4.</b> The exclude filter is evaluated last. Exclude filter starts with a minus sign. Example: <b>*\bin\*;<font color=red>-</font>*.exe </b>
<p>
The above example will match on the directory <b>bin</b> and all of its subdirectories and files. 
The exclude pattern will exclude all files with extension <b>.exe</b> from the matched files.
NOTE: The exclude only works on File and Wildcard filters and not simple Directory name filters.
The following will <font color=red>not</font> work because the members of bin directory are not tested individually.
<pre>
Example:  <b>bin\;-*.exe </b>
</pre>


 
<h2>Special Global Exclude Filter:</h2>

<p>If one or more exclude filters have their Filter name set
to <b><span style='color:#E36C0A'>'never'</span></b>, they are always evaluated
to prevent files from being located.  Remember to start the filter pattern with a minus sign.

<p> 
<blockquote>
Example:<br>
<table border=1>
<tr  style="background-color:#c0c0c0;"><td>Filter <td>Details <td>Description
<tr><td><b><span style='color:#E36C0A'>never-exe</span></b><td> -*.exe <td>Don't remove executables
<tr><td><b><span style='color:#E36C0A'>never-cpp</span></b><td> -*.cpp <td>Don't remove source files cpp
<tr><td><b><span style='color:#E36C0A'>never-zed</span></b><td> -*\Zed*\* <td>Don't remove Zed graph directories
</table>
</blockquote>


<p>Use <b>Add</b> and <b>Delete</b> buttons to manage your collection of filter rules.
<br><b>Double click</b> on a row to change its value.
<br><b>Right click</b> if you want to Export the filter rules as CSV
<br><Font color=red><b>Filter names must be unique. Duplicate filters will be ignored next time you restart.</b></font>


<h2>Bookmarks</h2>
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 <b>"Set"</b> button to refresh the current state of a selected bookmark to the current list of active filter rules and Path.


<h2>Keyboard</h2>
<blockquote>
         Control-A to select entire List
<br>     Space to toggle check boxes
<br>     Delete key to delete selected items or item under mouse
<br>     Up/Down to navigate up/down list and select row.
</blockquote>
     
<h2>Warning</h2>

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

<p>Sample screen of File and Directory List <b>Located</b> using default filters:
<center><img alt="selectedscreen" src="vstudioCleaner2.png"></center>


<h2>Points of Interest</h2>

<p>
While writing this application I learned the following:
<blockquote>
    1.	How to launch RegEdit and get it to open  on a specific registry entry   
<br>2.	How to force a listview to scroll to the left
<br>3.  Registering VStudioCleaner to folder menu.
<br>4.  Recursive pattern matcher
<br>5.  Inline html help text
</blockquote>

<p>
RegEdit like most Windows applications save their session settings in the registry.  
Before you launch RegEdit you simply set the value of <b>LastKey</b> in section  <b>Software\Microsoft\Windows\CurrentVersion\Applets\Regedit</b> to the registry path of your entries. 
<pre>  	  
      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);
          regEditKey.Close();

          // Launch RegEdit which will default at the last place it was (our stuff).
          System.Diagnostics.Process.Start("regedit.exe");
      }
</pre>
<p>
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.
<pre>

    for (int i = 0; i < shift; i++)
    {
        SendKeys.Send("{RIGHT}");
        SendKeys.Flush();
    }
</pre>

<p>
VStudioCleaner can be registered to appear in the <b>Shell Folder</b> popup menu.
<blockquote>
  Example of Option menu showing register selection:
  <p>
  <img alt="screen4" src="vstudioCleaner4.png" border=1>
</blockquote>

 
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.
<blockquote>
  Sample of menu when you right-click a folder, showing VStudioCleaner
  <p>
  <img alt="screen3" src="vstudioCleaner3.png" border=1>
</blockquote>


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

<pre>
        /// &lt;summary&gt;
        /// WildCompare supports simple '*' wildcard pattern.
        /// Returns true if pattern matches even if raw text has more characters.
        /// &lt;/summary&gt;
        /// &lt;returns&gt; true for partial match&lt;/returns&gt;
        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;

                    do
                    {
                        // Find match with char after '*'
                        while (rawOff < rawStr.Length &&
                            char.ToLower(rawStr[rawOff]) != char.ToLower(wildStr[wildOff + 1]))
                            rawOff++;
                        if (rawOff < rawStr.Length &&
                            WildCompare(wildStr, wildOff + 1, rawStr, rawOff))
                            return true;
                        ++rawOff;
                    } while (rawOff < rawStr.Length);

                    if (rawOff >= rawStr.Length)
                        return (wildStr[wildOff + 1] == '*');
                }
                else
                {
                    if (char.ToLower(rawStr[rawOff]) != char.ToLower(wildStr[wildOff]))
                        return false;
                    if (wildStr.Length == wildOff)
                        return true;
                    ++rawOff;
                }

                ++wildOff;
            }

            return true;
        }
</pre>


<p>Because the pattern matching is complex I added a popup help dialog, launched by pressing the &quot;?&quot; button. The original version used a <code>RichTextBox</code>. 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 <em>helpdialog.cs</em>. </p> 
 
<pre lang="cs">   
    public partial class HelpDialog : Form
    {
        public HelpDialog()
        {
            InitializeComponent();
 
            byte[] byteArray = Encoding.ASCII.GetBytes(helpHtml);
            MemoryStream mr = new MemoryStream(byteArray);
            this.webBrowser.DocumentStream = mr;
        }
 
        string helpHtml =
&quot;&lt;html&gt;&quot; +
&quot;&lt;body lang=EN-US&gt;&quot; +
&quot;&quot; +
&quot;&lt;p&gt;&lt;span style='font-size:12.0pt'&gt;Filters are patterns used to 
select directories and files.&lt;/span&gt;&quot; +
&quot;&lt;p&gt;&quot; +
&quot;&lt;b&gt;&lt;span style='font-size:12.0pt'&gt;Patterns fall into four categories:&lt;/span&gt;&lt;/b&gt;&quot; +
&quot;&quot; +
...
&quot;&lt;/body&gt;&quot; +
&quot;&lt;/html&gt;&quot;;
</pre> 


<h2>Final Words</h2>

This article is also publish on codeproject:
<blockquote>
<a href="http://www.codeproject.com/KB/cs/visual_studio_cleaner.aspx">
http://www.codeproject.com/KB/cs/visual_studio_cleaner.aspx</a>
</blockquote>
 
<p>
I want to thank Leonardo Paneque for providing his CodeProject "Solution Cleaner".
His home page is:
<blockquote>
<a href="http://www.teknowmagic.net/"> http://www.teknowmagic.net/ </a>
</blockquote>
    

<p>
A similar product is available from WiseCleaner:
<blockquote>
http://free-disk-cleaner.wisecleaner.com/disk-cleaner.htm
</blockquote>

<h2>Revision History</h2>

<blockquote>
<li class=LIw> Aug 23, 2009 v1.4
  <ul>
  <li class=LIa> Fixed threading bug, moved error messageBox to foreground thread
  </ul>
<li class=LIw> Aug 30, 2009 v1.5
  <ul>
  <li class=LIa> Fixed sorting size column when search limit reached and warning message in list table.
  <li class=LIa> Added inverse selection and delete NOW menu choices.
  </ul>
<li class=LIw> Sep 13, 2009 v1.6
  <ul>
  <li class=LIa> Added support for multiple 'never' filter entries. 'Never' only needs to be a prefix to a filter name.
  <li class=LIa> Added warning message box to NOW delete menu pick.
  <li class=LIa> Another fix to sorting columns with missing values.
  <li class=LIa> Updated help message.
  <li class=LIa> Fixed filescan dialog optional filter box to keep selection active when you click on the list.
  </ul>
<li class=LIw> Dec 17, 2011 v1.8
  <ul>
  <li class=LIa> Add foreground and background colors to filters
  <li class=LIa> Remember last bookmark and reset on startup. Show bookmark in title bar.
  <li class=LIa> Fix registry settings and viewing on Windows 7.
  <li class=LIa> Fixed multiple path list, will color direcotry red if directory is invalid.
  <li class=LIa> Fixed some delete error status messages.
  <li class=LIa> Fixed links in About box, fixed about box to resize.
  </ul>
</blockquote>

<a href=#top> Top </a>


<p> 
<div style="background-color:grey;">
<img src="/~lang.dennis/site/exec/counter.cgi">
</div>
<p>

</body>
</html>

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Dennis Lang
Software Developer (Senior) WSI
United States United States
30 years experience writing software.
I love C/C++ for its speed and power and C#/Visual Studio for quick application development.

Unix/Linux is my favorite OS

You may also be interested in...

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.150901.1 | Last Updated 18 Dec 2011
Article Copyright 2009 by Dennis Lang
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid