使用静态扩展方法
public static void Empty(this System.IO.DirectoryInfo directory)
{
foreach(System.IO.FileInfo file in directory.GetFiles()) file.Delete();
foreach(System.IO.DirectoryInfo subDirectory in directory.GetDirectories()) subDirectory.Delete(true);
}
System.IO.DirectoryInfo directory = new System.IO.DirectoryInfo(@"C:\指定的文件夹路径");
directory.Empty();
标签:文件,file,删除,C#,System,DirectoryInfo,IO,directory
From: https://www.cnblogs.com/nuomibaibai/p/17585476.html