...读取文件夹下面的所有文件夹和文件显示到TreeView中

...读取文件夹下面的所有文件夹和文件显示到TreeView中

2023年6月22日发(作者:)

C#Winform读取⽂件夹下⾯的所有⽂件夹和⽂件显⽰到TreeView中rtprivate void Form1_Load(object sender, EventArgs e) { PaintTreeView(ew1, "C:UsersHelloDocumentsVisual Studio2010WebSitesWebSite1Templates"); } #region ⽣成程序所在根⽬录的TreeView private void PaintTreeView(TreeView treeView, string fullPath) { try { (); //清空TreeView DirectoryInfo dirs = new DirectoryInfo(fullPath); //获得程序所在路径的⽬录对象 DirectoryInfo[] dir = ectories();//获得⽬录下⽂件夹对象 FileInfo[] file = es();//获得⽬录下⽂件对象 int dircount = ();//获得⽂件夹对象数量 int filecount = ();//获得⽂件对象数量 //循环⽂件夹 for (int i = 0; i < dircount; i++) { (dir[i].Name); string pathNode = fullPath + "" + dir[i].Name; GetMultiNode([i], pathNode); } //循环⽂件 for (int j = 0; j < filecount; j++) { (file[j].Name); } } catch (Exception ex) { (e + "rn出错的位置为:reeView()"); } } #endregion #region 遍历TreeView根节点下⽂件和⽂件夹 private bool GetMultiNode(TreeNode treeNode, string path) { if ((path) == false) { return false; } DirectoryInfo dirs = new DirectoryInfo(path); //获得程序所在路径的⽬录对象 DirectoryInfo[] dir = ectories();//获得⽬录下⽂件夹对象 FileInfo[] file = es();//获得⽬录下⽂件对象 int dircount = ();//获得⽂件夹对象数量 int filecount = ();//获得⽂件对象数量 int sumcount = dircount + filecount; if (sumcount == 0) { return false; } //循环⽂件夹 for (int j = 0; j < dircount; j++) { (dir[j].Name); string pathNodeB = path + "" + dir[j].Name; GetMultiNode([j], pathNodeB); } //循环⽂件 for (int j = 0; j < filecount; j++) { (file[j].Name); } return true; } } #endregion

发布者:admin,转转请注明出处:http://www.yc00.com/news/1687383132a5960.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信