I'm traveling through some shares to get information/permissions .. etc I'm using recursive to travel through all sub shares. it works fine however, the user should be able to limit the sub shares level to specific number which is a parameter in the application?
private static INodeCollection NodesLookUp(string path)
{
var shareCollectionNode = new ShareCollection(path);
// Do somethings
foreach (var directory in Directory.GetDirectories(shareCollectionNode.FullPath))
{
shareCollectionNode.AddNode(NodesLookUp(directory));
}
return shareCollectionNode;
}
this code will go all way to the lowest level, how can i stop it in specific level? for example get all shares until 2 levels only?
Thanks.
Rather than using a global variable to control the level, pass the maxLevel and decrement with each recursive call.
private static INodeCollection NodesLookUp(string path, int maxLevel)
{
var shareCollectionNode = new ShareCollection(path);
if (maxLevel > 0)
{
foreach (var directory in Directory.GetDirectories(shareCollectionNode.FullPath))
{
shareCollectionNode.AddNode(NodesLookup(directory, maxLevel-1));
}
}
return shareCollectionNode;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With