-
static public void DeleteFolder(string dir)
-
{
-
int num = 0;
-
foreach (string d in Directory.GetFileSystemEntries(dir))
-
{
-
if (File.Exists(d))
-
{
-
FileInfo fi = new FileInfo(d);
-
if (fi.Attributes.ToString().IndexOf("ReadOnly") != -1)
-
fi.Attributes = FileAttributes.Normal;
-
File.Delete(d);//直接删除其中的文件
-
num++;
-
}
-
else
-
{
-
DirectoryInfo d1 = new DirectoryInfo(d);
-
if (d1.GetFiles().Length != 0)
-
{
-
DeleteFolder(d1.FullName);递归删除子文件夹
-
}
-
Directory.Delete(d);
-
}
-
}
-
Console.WriteLine(dir + "共" + num + "个文件");
-
}
null
转载于:https://www.cnblogs.com/xiejunzhao/p/6441235.html