1 /// <summary>
2 /// 作用:创建与源文件夹相同结构的目录
3 /// </summary>
4 /// <param name="dir">源文件夹目录</param>
5 /// <param name="p">目标文件夹路径</param>
6 private bool CopyDirectory(DirectoryInfo sour, string des)
7 {
8 bool falg = true;
9 try
10 {
11 if (Directory.Exists(des))
12 {
13 if (MessageBox.Show("该文件夹已存在,是否覆盖?", "系统提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
14 {
15 Directory.Delete(des, true);
16 }
17 else
18 {
19 return false;
20 }
21 }
22 Directory.CreateDirectory(des);
23
24 //依次向下遍历
25 foreach (DirectoryInfo subDirs in sour.GetDirectories())
26 {
27 CopyDirectory(subDirs, des + "\\" + subDirs.Name + "\\");
28 }
29 }
30 catch(Exception ex)
31 {
32 falg = false;
33 return false;
34 }
35 return falg;
36 }