2023-03-10
This commit is contained in:
@@ -567,6 +567,55 @@ namespace BLL
|
||||
return str;
|
||||
}
|
||||
|
||||
public static bool DeleteDir(string file)
|
||||
{
|
||||
|
||||
try
|
||||
{
|
||||
//去除文件夹和子文件的只读属性
|
||||
//去除文件夹的只读属性
|
||||
System.IO.DirectoryInfo fileInfo = new DirectoryInfo(file);
|
||||
fileInfo.Attributes = FileAttributes.Normal & FileAttributes.Directory;
|
||||
|
||||
//去除文件的只读属性
|
||||
System.IO.File.SetAttributes(file, System.IO.FileAttributes.Normal);
|
||||
|
||||
//判断文件夹是否还存在
|
||||
if (Directory.Exists(file))
|
||||
{
|
||||
|
||||
foreach (string f in Directory.GetFileSystemEntries(file))
|
||||
{
|
||||
|
||||
if (File.Exists(f))
|
||||
{
|
||||
//如果有子文件删除文件
|
||||
File.Delete(f);
|
||||
Console.WriteLine(f);
|
||||
}
|
||||
else
|
||||
{
|
||||
//循环递归删除子文件夹
|
||||
DeleteDir(f);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//删除空文件夹
|
||||
|
||||
Directory.Delete(file);
|
||||
|
||||
}
|
||||
return true;
|
||||
}
|
||||
catch (Exception ex) // 异常处理
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
#region 时间转换
|
||||
/// <summary>
|
||||
/// 输入文本转换时间类型
|
||||
|
||||
Reference in New Issue
Block a user