title: Sorting a folder of Visual Studio solutions by last write time
body: <p>I have a folder with a bunch of Visual Studio 2010 solution folders in it.</p>
  
  <p>In Windows Explorer, I'm sorting the folder in descending order of 'Date modified'.</p>
  
  <p>If I modify a C# file deep in a solution folder somewhere, I'd like that solution folder to move to the top of the explorer listing. I.e. I'd like to have that folder be considered "modified".</p>
  
  <p>Is there an extension to Visual Studio that enables this behavior? Or is there a more straightforward way to sort solutions such that the most recently modified ones appear first in Windows Explorer?</p>
  
  <p>I threw together this C# program which uses <code>FileSystemWatcher</code> to monitor a folder for changes to <code>*.cs</code> files and touches it's corresponding VS solution folder. However, the call <code>Directory.SetLastWriteTime(path, DateTime.Now)</code> results in an exeption; it appears that when VS has a solution open, that directory is locked such that the <code>SetLastWriteTime</code> cannot update the time.</p>
  
  <pre><code>using System;
  using System.IO;
  
  namespace MyDocumentsWatcher
  {
      class Program
      {
          static void Main(string[] args)
          {
              var watcher =
                  new FileSystemWatcher()
                  {
                      Path = "C:/Users/dharmatech/Documents",
                      Filter = "*.cs",
                      NotifyFilter = 
                          NotifyFilters.LastWrite |
                          NotifyFilters.FileName |
                          NotifyFilters.DirectoryName,
                      IncludeSubdirectories = true,
                      EnableRaisingEvents = true
                  };
  
              watcher.Changed += (s, e) =&gt;
                  {
                      Console.WriteLine("{0} {1}", e.ChangeType, e.Name);
  
                      var path = e.FullPath;
  
                      while (true)
                      {
                          Console.WriteLine(path);
                          if (Path.GetDirectoryName(path) == @"C:\Users\dharmatech\Documents")
                          {
                              Directory.SetLastWriteTime(path, DateTime.Now);
                              break;
                          }
                          else
                              path = Path.GetDirectoryName(path);
                          System.Threading.Thread.Sleep(1000);
                      }
                  };
  
              Console.ReadLine();
          }
      }
  }
  </code></pre>
  
  <p>Any suggestions for how to achieve this are welcome!</p>