发布:2022/3/3 9:19:58作者:管理员 来源:本站 浏览次数:831
代码如下:
复制代码
/// <summary>
/// 删除文件夹以及文件
/// </summary>
/// <param name="directoryPath"> 文件夹路径 </param>
/// <param name="fileName"> 文件名称 </param>
public static void DeleteDirectory(string directoryPath, string fileName)
{
//删除文件
for (int i = 0; i < Directory.GetFiles(directoryPath).ToList().Count; i++)
{
if (Directory.GetFiles(directoryPath)[i] == fileName)
{
File.Delete(fileName);
}
}
//删除文件夹
for (int i = 0; i < Directory.GetDirectories(directoryPath).ToList().Count; i++)
{
if (Directory.GetDirectories(directoryPath)[i] == fileName)
{
Directory.Delete(fileName, true);
}
}
}
复制代码
调用方式:
删除文件
DeleteDirectory(@"D:\copyfile\zip", @"D:\copyfile\zip\20180916115334.zip");
删除文件夹
DeleteDirectory(@"D:\copyfile\zip", @"D:\copyfile\zip\20180916115334");
© Copyright 2014 - 2024 柏港建站平台 ejk5.com. 渝ICP备16000791号-4