title: C# Sorting Directory Names using LINQ
body: <p>I found something similar <a href="https://stackoverflow.com/questions/6956672/how-to-retrieve-list-of-files-in-directory-sorted-by-name">here</a> but have been unable to get it working. I'm very new to LINQ and so not entirely sure what's going on with it. Any help would be appreciated. I have directory names like:</p>
  
  <pre><code>directory-1
  article-about-something-else
  </code></pre>
  
  <p>I want to sort these by name but have been unable thus far. They are on a network drive residing on a RedHat server. The directory listing comes in a garbled mess in a seemingly random order.</p>
  
  <p>Here's some of what I've tried:</p>
  
  <pre class="lang-cs prettyprint-override"><code>DirectoryInfo dirInfo = new DirectoryInfo("Z:\\2013");
  var dirs = dirInfo.GetDirectories().OrderBy(d =&gt; dirInfo.Name);
  foreach (DirectoryInfo dir in dirs)
  {
      string month = dir.Name;
      Console.WriteLine(dir.Name);
      var monthDirInfo = new DirectoryInfo("Z:\\2013\\" + month);
      var monthDirs = monthDirInfo.GetDirectories().OrderBy(d =&gt; monthDirInfo.CreationTime);
      foreach (DirectoryInfo monthDir in monthDirs)
      {
          string article = monthDir.Name;
          Console.WriteLine(monthDir.Name);
          sb.AppendLine("&lt;li&gt;&lt;a href=\"/2013/" + month + "/" + article + "\"&gt;" + TextMethods.GetTitleByUrl("2013/" + month + "/" + article) + "&lt;/a&gt;&lt;/li&gt;");
      }
  }
  </code></pre>
  
  <p>Any help would be greatly appreciated. I'm sort of at a loss at the moment. I'm sure I'm missing something obvious, too.</p>