1 /// <summary> 2 /// 复制源目录及文件到另一个目录下 3 /// </summary> 4 /// <param name="srcDir">源目录</param> 5 /// <param name="destDir">目标目录</param> 6 /// <param name="recursion">是否递归复制</param> 7 private void DirectoryCopy(string srcDir, string destDir, bool recursion) 8 { 9 try 10 { 11 var di = new DirectoryInfo(srcDir); 12 var fsis = di.GetFileSystemInfos(); 13 14 foreach (var item in fsis) 15 { 16 // 目录复制 17 if (item is DirectoryInfo) 18 { 19 Directory.CreateDirectory(Path.Combine(destDir, item.Name)); 20 21 // 递归复制子目录 22 if (recursion) 23 { 24 DirectoryCopy(item.FullName, Path.Combine(destDir, item.Name)); 25 } 26 } 27 else 28 { 29 // 文件复制 30 File.Copy(item.FullName, Path.Combine(destDir, item.Name), true); 31 } 32 } 33 } 34 catch (Exception) 35 { 36 throw; 37 } 38 }
标签:Name,源目录,destDir,item,复制,Combine,目录 From: https://www.cnblogs.com/baymaxwh/p/17377075.html