zoukankan      html  css  js  c++  java
  • C#遍历文件夹构造文件树

    1. private void Form1_Load(object sender, EventArgs e)   
    2.        {   
    3.            TreeNode root = new TreeNode();   
    4.            root.Text = "目录";   
    5.            GetFiles(@"E:\Tools", root);   
    6.            treeView1.Nodes.Add(root);   
    7.   
    8.        }   
    9.   
    10.   
    11.        private void GetFiles(string filePath, TreeNode node)   
    12.        {   
    13.            DirectoryInfo folder = new DirectoryInfo(filePath);   
    14.            node.Text = folder.Name;   
    15.            node.Tag = folder.FullName;   
    16.               
    17.            FileInfo[] chldFiles = folder.GetFiles("*.*");   
    18.            foreach (FileInfo chlFile in chldFiles)   
    19.            {   
    20.                TreeNode chldNode = new TreeNode();   
    21.                chldNode.Text = chlFile.Name;   
    22.                chldNode.Tag = chlFile.FullName;   
    23.                node.Nodes.Add(chldNode);   
    24.            }   
    25.   
    26.            DirectoryInfo[] chldFolders = folder.GetDirectories();   
    27.            foreach (DirectoryInfo chldFolder in chldFolders)   
    28.            {   
    29.                TreeNode chldNode = new TreeNode();   
    30.                chldNode.Text = folder.Name;   
    31.                chldNode.Tag = folder.FullName;   
    32.                node.Nodes.Add(chldNode);   
    33.                GetFiles(chldFolder.FullName, chldNode);   
    34.            }   
    35.               
    36.        }  
  • 相关阅读:
    [GSEAPY] 在Python里进行基因集富集分析
    scRNAseq R包公共单细胞数据获取
    pybedtools:在Python中使用BEDTools
    pybedtools 提取序列
    将博客搬至CSDN
    【转】SELECT INTO 和 INSERT INTO SELECT 两种表复制语句
    sql长日期数据以短日期格式显示【转】
    [转]YouTube架构学习体会
    [转]让Nginx 支持 ASP ASP.NET配置方法
    [转]LINQ查询总结
  • 原文地址:https://www.cnblogs.com/kingboy2008/p/2055596.html
Copyright © 2011-2022 走看看