删除带通配符的多个文件 [英] Deleting multiple files with wildcard
本文介绍了删除带通配符的多个文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您知道,在linux下很容易,但我不能只理解如何做它在C#在Windows上。我想删除匹配通配符 F * .TXT
中的所有文件。我该如何去准备呢?
You know that in linux it's easy but I can't just understand how to do it in C# on Windows. I want to delete all files matching the wildcard f*.txt
. How do I go about going that?
推荐答案
您可以使用的 DirectoryInfo.EnumerateFiles
功能:
You can use the DirectoryInfo.EnumerateFiles
function:
var dir = new DirectoryInfo(directoryPath);
foreach (var file in dir.EnumerateFiles("f*.txt")) {
file.Delete();
}
(当然,你可能需要添加错误处理。)
(Of course, you'll probably want to add error handling.)
这篇关于删除带通配符的多个文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文