递归删除文件和文件夹
程序员文章站
2022-05-14 22:56:54
...
public static void DeleteSpecificFolder(string dir,string delName)
{
if (Directory.Exists(dir))
{
var dirs = Directory.GetDirectories(dir);
dirs.ToList().ForEach(s =>
{
var di = new DirectoryInfo(s);
if (di.Name == delName)
{
Directory.Delete(s, true);
}
else
{
DeleteSpecificFolder(s, delName);
}
});
}
}
public static void DeleteSpecificFile(string dir, string fileExtension)
{
if (Directory.Exists(dir))
{
var fs = Directory.GetFiles(dir);
fs.ToList().ForEach(s =>
{
string ext = Path.GetExtension(s);
if (ext == fileExtension)
{
File.Delete(s);
}
});
var dirs = Directory.GetDirectories(dir);
dirs.ToList().ForEach(s =>
{
DeleteSpecificFile(s, fileExtension);
});
}
}
上一篇: vue复制功能,点击复制input内容
下一篇: Vue实现点击按钮复制文本内容