So I have a directory where a bunch of configuration files are stored, but now I also have several sub directories which also contain config files. I had a function for collecting all configuration files per station, but now it's only collecting files in the directory, not the sub folders. old code:
string MasterList = "ConfigsForStation1.txt";
string dirC = "..\\config\\Station1\\";
foreach (FileInfo fileC in dirC.GetFiles())
{
if(!System.IO.Path.GetExtension(fileC.FullName).EndsWith(".confg"))
{ WriteToList(fileC,MasterList);}
}
and now with this sub directory stuff implemented its more along these lines:
string MasterList = ...;
string dirC = ...;
//collect files in sub directories substations 1 & 2
foreach(DirectoryInfo Dx in dirC.GetDirectories())
{ foreach(FileInfo fileC in Dx.GetFiles())
{...}
}
//collect files in parent directory station 1
foreach(FileInfo fileC in dirC.GetFiles())
{...}
my question is: is there a cleaner way to collect files from all sub folders rather then nest a foreach inside of a foreach? and then do a third pass for the stuff in parent. It feels abit sloppy and I feel like theres some command like dirC.getAllsub() that will do so for me? just looking for hints and ideas to clean up the code.