0

I'm having some trouble generating an output in my last for loop. I'm suposed to be generating a list of folders that fit the criteria in the double for loop but black screen is just stuck doesnt even display the press any key to exit messsage. Help would be much appreciated

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();
}

} }

JPhillips
  • 59
  • 1
  • 5
  • inside the inner for loop i have added instead of : 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()); i have done an if statement and im returning something really fast. is it possible to put what i had before into an if statement guys? – JPhillips May 25 '16 at 20:11
  • Please edit your question if you've got additional information. – Gert Arnold May 25 '16 at 20:50
  • You're throwing away exceptions with the statement `catch (Exception e) { }`. Disable the `try/catch` and you'll likely get an exception telling you what the problem is. – Tone May 25 '16 at 20:53

0 Answers0