我有个递归算法的例子,不知道是否适合你的要求。
example: FillDirectory(@"c:\test","DotNet");using System.Windows .Forms;
using System.IO;
using System;public static TreeNode FillDirectory(string dirFullPath, string nodesName)
{
  //new DirectoryInfo w/ full path
   DirectoryInfo di = new DirectoryInfo(dirFullPath); 
 
  //Number of directires
   int numOfDirectories = di.GetDirectories().Length;    //holds array of directories
    DirectoryInfo[] tempdi = di.GetDirectories(); 
//create array of TreeNode for child nodes
    TreeNode[] subRoot = new TreeNode[numOfDirectories];     for(int i=0; i<numOfDirectories; i++)
    {
      subRoot[i]=FillDirectory(tempdi[i].FullName,tempdi[i].Name);

    }    //creat final node with childnodes in it
    TreeNode root = new TreeNode(dirFullPath,subRoot);     return root; //return the final node   }
微软亚洲技术中心 VC技术支持本贴子仅供CSDN的用户作为参考信息使用。其内容不具备任何法律保障。您需要考虑到并承担使用此信息可能带来的风险。具体事项可参见使用条款 (http://www.csdn.net/microsoft/terms.shtm)。