标签:list dir TreeView returns new foreach tag ret return
/// <summary>
/// TreeView获取目录下的所有文件
/// </summary>
/// <param name="tree"></param>
/// <param name="dirname"></param>
/// <returns></returns>
public static bool InitTreeView(TreeView tree, List<TreeNode> filenodes)
{
tree.Nodes.Clear();
foreach (TreeNode filenode in filenodes)
{
TreeNode root = new TreeNode(filenode.Name + "批次列表文件");
//if ((root = getRootNode(dirname)) == null)
// return false;
getRootNode(filenode.Tag.ToString(), root);
tree.Nodes.Add(root);
}
//root.Expand();
return true;
}
private static void getRootNode(string dirname, TreeNode treenode) //递归,返回根结点
{
treenode.Tag = dirname;
string[] dirs = Directory.GetDirectories(dirname);
string[] files = Directory.GetFiles(dirname);
foreach (string dir in dirs)
{
FileInfo fileinfo = new FileInfo(dir);
TreeNode node = new TreeNode(fileinfo.Name);
node.Tag = dir;
getRootNode(dir, node);
treenode.Nodes.Add(node);
}
foreach (string file in files)
{
FileInfo fileinfo1 = new FileInfo(file);
TreeNode fnode = new TreeNode(fileinfo1.Name);
fnode.Tag = file;
treenode.Nodes.Add(fnode);
}
}
标签:list dir TreeView returns new foreach tag ret return
原文地址:http://www.cnblogs.com/liuyongpingblog/p/7244388.html