zoukankan      html  css  js  c++  java
  • 使用递归列出文件夹目录及目录下的文件

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    using System.IO;

    namespace 使用递归列出文件夹目录及目录下的文件
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }

            private void Form1_Load(object sender, EventArgs e)
            {
                string path = "D:\Notes";
                TreeNode node = treeView1.Nodes.Add(path);
                DirectoryToTree(path, node.Nodes);
            }

            private void DirectoryToTree(string path, TreeNodeCollection nodes)
            {
                foreach (string item in Directory.GetDirectories(path))
                {
                    TreeNode node = nodes.Add(Path.GetFileName(item));
                    DirectoryToTree(item, node.Nodes);

                }
                string[] strFiles = Directory.GetFiles(path);
                foreach (string str in strFiles)
                {
                    nodes.Add(Path.GetFileName(str));
                }
            }
        }
    }

    image

  • 相关阅读:
    Winget
    全部所学知识
    重装系统
    srs更改端口号导致webrtc播放异常
    .NET性能优化方面的总结(转)
    从自动变换页面背景CSS改写成变换背景图
    网页级在线性能网站测试介绍
    ASP.NET服务器端控件学习(一)
    Nginx源码分析内存池
    使用Memcached提高.NET应用程序的性能
  • 原文地址:https://www.cnblogs.com/HarryChis/p/10460074.html
Copyright © 2011-2022 走看看