using System.IO;
 
public static void DeleteDirectory(string targetDir)
{
    string[] files = Directory.GetFiles(targetDir);
    string[] dirs = Directory.GetDirectories(targetDir);
 
    foreach (string file in files)
    {
        File.SetAttributes(file, FileAttributes.Normal);
        File.Delete(file);
    }
 
    foreach (string dir in dirs)
    {
        DeleteDirectory(dir);
    }
 
    Directory.Delete(targetDir, true);
}

 

posted on 2024-05-17 11:12  邢帅杰  阅读(125)  评论(0编辑  收藏  举报