1 private static void CopyFolder( string srcFolder, string destFolder ) {
2 if (!Directory.Exists(destFolder)) {
3 Directory.CreateDirectory( destFolder );
4 }
5 foreach (var item in Directory.EnumerateFiles(srcFolder)) {
6 File.Copy( item, Path.Combine( destFolder, Path.GetFileName( item ) ), true );
7 }
8 foreach (var item in Directory.EnumerateDirectories(srcFolder)) {
9 CopyFolder(item,Path.Combine(destFolder,Path.GetFileName(item)));
10 }
11 }
2 if (!Directory.Exists(destFolder)) {
3 Directory.CreateDirectory( destFolder );
4 }
5 foreach (var item in Directory.EnumerateFiles(srcFolder)) {
6 File.Copy( item, Path.Combine( destFolder, Path.GetFileName( item ) ), true );
7 }
8 foreach (var item in Directory.EnumerateDirectories(srcFolder)) {
9 CopyFolder(item,Path.Combine(destFolder,Path.GetFileName(item)));
10 }
11 }
可以自由指定目标目录名称,srcFolder和destFolder是同级目录。