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); } } } } |
|