- private void Form1_Load(object sender, EventArgs e)
- {
-
TreeNode root = new TreeNode();
-
root.Text = "目录";
-
GetFiles(@"E:\Tools", root);
- treeView1.Nodes.Add(root);
-
- }
-
-
-
private void GetFiles(string filePath, TreeNode node)
- {
-
DirectoryInfo folder = new DirectoryInfo(filePath);
- node.Text = folder.Name;
- node.Tag = folder.FullName;
-
-
FileInfo[] chldFiles = folder.GetFiles("*.*");
-
foreach (FileInfo chlFile in chldFiles)
- {
-
TreeNode chldNode = new TreeNode();
- chldNode.Text = chlFile.Name;
- chldNode.Tag = chlFile.FullName;
- node.Nodes.Add(chldNode);
- }
-
- DirectoryInfo[] chldFolders = folder.GetDirectories();
-
foreach (DirectoryInfo chldFolder in chldFolders)
- {
-
TreeNode chldNode = new TreeNode();
- chldNode.Text = folder.Name;
- chldNode.Tag = folder.FullName;
- node.Nodes.Add(chldNode);
- GetFiles(chldFolder.FullName, chldNode);
- }
-
- }