-1

I need to search a root folder for particular subdirectory named "XYZ","ABC". And need to get the filenames from these two folder by iterating these two folder one by one.

I have used the below code to find subdirectory but not sure how to find filenames from this list.

IEnumerable<string> list = Directory.GetDirectories(root).Where(s => s.Equals("XYZ"));
Tech Learner
  • 1,227
  • 6
  • 24
  • 59

1 Answers1

0

The easiest way would be:

List<string> allFiles = new List<string>();
foreach (string subDir in list)
    allFiles.AddRange (Directory.GetFiles (subDir));

The result is all files in both directories in one list with full path included.

SomeCoder
  • 126
  • 6