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

  • 相关阅读:
    算法训练 P1103
    算法训练 表达式计算
    算法训练 表达式计算
    基础练习 时间转换
    基础练习 字符串对比
    Codeforces 527D Clique Problem
    Codeforces 527C Glass Carving
    Codeforces 527B Error Correct System
    Codeforces 527A Glass Carving
    Topcoder SRM 655 DIV1 250 CountryGroupHard
  • 原文地址:https://www.cnblogs.com/HarryChis/p/10460074.html
Copyright © 2011-2022 走看看