Có cách nào để xóa tất cả các tệp & thư mục con của một thư mục được chỉ định mà không cần lặp lại chúng không?Cách tốt nhất để dọn sạch thư mục là gì?
Giải pháp không thanh lịch:
public static void EmptyDirectory(string path)
{
if (Directory.Exists(path))
{
// Delete all files
foreach (var file in Directory.GetFiles(path))
{
File.Delete(file);
}
// Delete all folders
foreach (var directory in Directory.GetDirectories(path))
{
Directory.Delete(directory, true);
}
}
}
http://social.msdn.microsoft.com/Forums/vstudio/en-US/2239b45a-3f19-4a2a-b5cd-050b3ee32b9d/how-can-i-check-folder-is-empty-or-not ? forum = csharpgeneral –