Looping a directory with subdirectories?

Oct 5 2007 11:59 AM
I am working on a windows application in VS2005 C#. The problem is that I will read a directory for files. I have a foreach so I can loop al the files in the directory. Know I wil do the same but for the subdirectories also. So I think there must be a second foreach and place the subdir in the method. Someone who can help me??


Here is some test code:

public void test(String path)
{
DirectoryInfo root = new DirectoryInfo(path);

DirectoryInfo[] dirs = root.GetDirectories();

String bla = "";
foreach (DirectoryInfo subDir in dirs)
{
bla += subDir.Name.ToString()+"-----";
}
richTextBox1.Text = bla;
}

Answers (3)