I'm calling this function to load a TreeView with a list of the directories on the disk.
private void LoadDirectories(string currentPath, TreeNodeCollection nodes)
{
DirectoryInfo directoryInfo = new DirectoryInfo(currentPath);
DirectoryInfo[] directories = directoryInfo.GetDirectories();
foreach (DirectoryInfo dir in directories)
{
if ((dir.Attributes & FileAttributes.System) != FileAttributes.System &&
(dir.Attributes & FileAttributes.Hidden) != FileAttributes.Hidden)
{
TreeNode newNode = nodes.Add(dir.Name);
LoadDirectories(dir.FullName, newNode.Nodes);
}
}
}
If I comment out the recursive call I get all of the subdirectories in the tree. If I don't I don't. Some directories are missing. I'm not sure what is going on.
Help?
Scott