分享

VA18.__资源管理器

 时间剧毒 2020-01-17

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Text;

using System.Windows.Forms;

using System.IO;

namespace VA18.__资源管理器

{

    public partial class Form1 : Form

    {

        public Form1()

        {

            InitializeComponent();

        }

        private void Form1_Load(object sender, EventArgs e)

        {

            string path=@"D:\资料";

            LoadData(path, this.treeView1.Nodes);

        }

        //Directory 关于目录的操作

        //File 关于文件操作

        private void LoadData(string path, TreeNodeCollection treeNodeCollection)

        {    

             //1获取path下的所有文件夹

            string[] dirs = Directory.GetDirectories(path);

            foreach (string itms in dirs) {

                TreeNode tnode = treeNodeCollection.Add(Path.GetFileName(itms));

                LoadData(itms, tnode.Nodes);

            }

            //2获取path下的所有文件

            string[] files = Directory.GetFiles (path,"*.txt");

            foreach (string itms in files) {

                TreeNode node = treeNodeCollection.Add(Path.GetFileName(itms));

                node.Tag = itms; 

            }

        }

        private void treeView1_NodeMouseDoubleClick(object sender, TreeNodeMouseClickEventArgs e)

        {

            if (e.Node.Tag != null) {

                this.textBox1.Text = File.ReadAllText(e.Node.Tag.ToString (),Encoding.Default);

            }

        }

    }

}

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多