addrange目录没有输出查询

时间:2016-05-25 19:39:58

标签: c# linq list subdirectory addrange

我在上一个for循环中生成输出时遇到了一些麻烦。我倾向于生成符合双循环标准的文件夹列表,但黑屏只是卡住甚至不显示按任意键退出消息。非常感谢帮助

namespace ArchivingApplication
{
  class Program
  {
    static void Main()
    {
      //regex pattern to get folder names of the type #.#.#.#/#. something
      Regex reg = new Regex(@"\d+(\.\d+)+");

  //setting where to start looking
  DirectoryInfo root = new DirectoryInfo(@"\\Visrep01\references");
  DirectoryInfo[] parent = root.GetDirectories();
  DirectoryInfo[] subDirectories = null;
  List<DirectoryInfo> candidates = new List<DirectoryInfo>();

  try
  {
    foreach (DirectoryInfo directory in parent)
    {
      subDirectories = directory.GetDirectories();
      Console.WriteLine(directory);
      foreach (DirectoryInfo subdirectory in subDirectories)
      {
       //Console.WriteLine(subdirectory);
       candidates.AddRange(subdirectory.GetDirectories("*",SearchOption.AllDirectories).Where(d => reg.IsMatch(d.Name)).Where(d => !d.FullName.EndsWith("TESTS")).Where(d => !(d.GetDirectories().Length == 0 && d.GetFiles().Length == 0)).ToList());   
      }
    }
  }
  catch (Exception e) { }

 foreach(DirectoryInfo dir in candidates)
  {
    Console.WriteLine(dir.FullName);
  }
  //keep the application in debug mode
  Console.WriteLine("Press any key to exit.");
  Console.ReadKey();
}

} }

0 个答案:

没有答案