treeList获取目录下的所有文件

 

/// <summary>
/// treeList获取目录下的所有文件
/// </summary>
public static void InitTreeListGetFiles(TreeList treeListFiles, string strPath)
{
treeListFiles.Nodes.Clear();
//TreeListNode root = treeListFiles.AppendNode(new object[] { " " }, -1);
TreeListNode firstNode = getRootListNode(treeListFiles, strPath, -1);
}

/// <summary>
/// </summary>
/// <param name="treeListFiles"></param>
/// <param name="dirname"></param>
/// <param name="node"></param>
/// <returns></returns>
private static TreeListNode getRootListNode(TreeList treeListFiles, string dirname, int nodeID) //递归,返回根结点
{
if (!Directory.Exists(dirname))
return null;

string[] dirs = Directory.GetDirectories(dirname);
string[] files = Directory.GetFiles(dirname);

foreach (string dir in dirs)
{
TreeListNode root2 = treeListFiles.AppendNode(new object[] { dir }, nodeID);
TreeListNode node2 = getRootListNode(treeListFiles, dir, root2.Id);
}


foreach (string file in files)
{
TreeListNode node2 = treeListFiles.AppendNode(new object[] { file }, nodeID, 1, 1, 0);
}

return treeListFiles.Nodes.FirstNode;
}

posted @ 2017-07-27 13:34  随笔`  阅读(612)  评论(0编辑  收藏  举报