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?
f*.txt
You can use the DirectoryInfo.EnumerateFiles function:
DirectoryInfo.EnumerateFiles
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.)
1.4m articles
1.4m replys
5 comments
57.0k users