using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Windows.Forms;using System.IO;namespace WindowsFormsApplication24{ public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { TreeNode tn = treeView1.Nodes.Add("zwj"); string path = textBox1.Text;// @"C:\Users\Administrator\Desktop\code"; SearchFile(path, tn,@"aa\"); } ////// 文件夹拷贝 /// /// 拷贝的来源 /// 绑定到TreeNode /// 设置根目录路径 private void SearchFile(string v, TreeNode tn,string path) { string[] dires = Directory.GetDirectories(v,"*.*"); string[] files = Directory.GetFiles(v, "*.*"); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } foreach (var item in files) { tn.Nodes.Add(item.ToString()); File.Copy(item, path + @"\"+Path.GetFileName(item), true); } foreach (var item in dires) { TreeNode tsub = tn.Nodes.Add(item); string p1 = path + item.Replace(v, ""); if (!Directory.Exists( p1)) { //string str = Directory.GetParent(item).ToString(); Directory.CreateDirectory( p1); } SearchFile(item, tsub,p1);// 递归调用 } } }}