prongs prongs - 1 year ago 99
C# Question

Deleting multiple files with wildcard

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

. How do I go about going that?

Answer Source

You can use the DirectoryInfo.EnumerateFiles function:

var dir = new DirectoryInfo(directoryPath);

foreach (var file in dir.EnumerateFiles("f*.txt")) {

(Of course, you'll probably want to add error handling.)

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download