I've got a function that currently grabs all folders and sub-folders to check the ACL's for a small tool I'm building but I'm pulling my hair out trying to figure out how to limit the depth that it can go to. For example you have a folder that goes 4 levels deep but I want to be able to only grab 3 levels of it for ACL's.
Currently I have it coded thusly:
private void StepThroughDirectories(string dir)
{
string[] directories = Directory.GetDirectories(dir);
try
{
foreach (string d in Directory.GetDirectories(dir))
{
if (recCount < (int)Depth)
{
GetACLs(d, new DirectoryInfo(d));
pBar.Value += 1;
//MessageBox.Show("Recursive Level: " + counter.ToString());
recCount++;
StepThroughDirectories(d);
}
else
{
recCount--;
}
}
}
catch (System.Exception e)
{
Console.WriteLine(e.Message);
}
}
Obviously that's not as nice as it was because I've been working on the problem for a little while but if anyone can point me in the right direction to solve this issue I would be very happy!