1internal void CopyDirectory(string source, string destination)
2{
3 if (destination[destination.Length - 1] != Path.DirectorySeparatorChar)
4 {
5 destination += Path.DirectorySeparatorChar;
6 }
7
8 if (!Directory.Exists(destination))
9 {
10 Directory.CreateDirectory(destination);
11 }
12
13 string[] fileSystemEntries = Directory.GetFileSystemEntries(source);
14 foreach (string entry in fileSystemEntries)
15 {
16 if (Directory.Exists(entry))
17 {
18 // It's a subdirectory so recurse
19 CopyDirectory(entry, destination + Path.GetFileName(entry));
20 }
21 else
22 {
23 // It's a file so copy it
24 File.Copy(entry, destination + Path.GetFileName(entry), true);
25 }
26 }
27}