删除文件夹下的文件和文件夹
1 /// <summary> 2 /// 删除文件夹下的文件和文件夹 3 /// </summary> 4 /// <param name="directoryPath"></param> 5 public static void DeleteFolder(string directoryPath) 6 { 7 foreach (string d in Directory.GetFileSystemEntries(directoryPath)) 8 { 9 if (File.Exists(d)) 10 { 11 File.Delete(d); //删除文件 12 } 13 else 14 DeleteFolder(d); //删除文件夹 15 } 16 Directory.Delete(directoryPath); 17 }