public static void CopyDirectory(string srcdir, string desdir, List <string> filterList) { string str1 = srcdir.Substring(srcdir.LastIndexOf("\\") + 1); string str2 = desdir + "\\" + str1; if (desdir.LastIndexOf("\\") == desdir.Length - 1) { str2 = desdir + str1; } foreach (string fileSystemEntry in Directory.GetFileSystemEntries(srcdir)) { if (Directory.Exists(fileSystemEntry)) { string path = str2 + "\\" + fileSystemEntry.Substring(fileSystemEntry.LastIndexOf("\\") + 1); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } UtilFile.CopyDirectory(fileSystemEntry, str2, filterList); } else { string str3 = fileSystemEntry.Substring(fileSystemEntry.LastIndexOf("\\") + 1); string destFileName = str2 + "\\" + str3; if (!Directory.Exists(str2)) { Directory.CreateDirectory(str2); } if (UtilFile.IsVaildFilter(filterList, fileSystemEntry)) { File.Copy(fileSystemEntry, destFileName); } } } }