I’m trying to enumerate the directories and sub directories in a Windows Form using a Tree View. I can view the directories but when I want to see the files in the sub directories I only see the files from the root.
private void button1_Click(object sender, EventArgs e)
{
try
{
string path = @"e:\\\\";
TreeNode rootNode = treeView1.Nodes.Add("e:\\\\");
DirectoryInfo a = new DirectoryInfo(path);
FileInfo[] cc = a.GetFiles("*.*");
foreach (DirectoryInfo b in a.GetDirectories())
{
TreeNode aa = new TreeNode(b.FullName);
rootNode.Nodes.Add(aa);
// TreeNode bb = new TreeNode(cc.FullName);
// aa.Nodes.Add(bb);
foreach (FileInfo dd in a.GetFiles())
{
TreeNode bb = new TreeNode(dd.FullName);
aa.Nodes.Add(bb);
}
}
}
catch (UnauthorizedAccessException c)
{
txtError.Text += c.Message;
}
catch (IOException d)
{
txtError.Text += d.Message;
}
}