写一个简单的递归函数

private void button1_Click(object sender, System.EventArgs e)
{
digui(this.textBox1.Text);
}
private void digui(string path)
{
DirectoryInfo di=new DirectoryInfo(path);
FileInfo[] SubFiles=di.GetFiles();

FileSystemInfo[] dirs = di.GetDirectories();
this.richTextBox1.Text+=di.Name+"\r\n";
//添加当前目录下的文件
foreach(FileInfo fileNext in SubFiles)
{
this.richTextBox1.Text+="****"+fileNext.Name+"\r\n";
}

//子目录递归
foreach(DirectoryInfo diNext in dirs)
{
this.richTextBox1.Text+="****";
digui(diNext.FullName);

}
}

=========
效果:
a
****c.txt
****b
****e.txt
应该是:
a
****c.txt
****b
********e.txt

你可能感兴趣的:(C++,c,C#)