ASP.NET File.Delete with a Wildcard

I wanted to delete all files within a directory that have a certain string in it, but File.Delete doesn’t allow wildcards. So, I wrote up this little tid-bit that cleared up that problem =)

Dim files() As String = Directory.GetFiles(Server.MapPath(“/Directory/”), “*” strMatchingString “.*”)
Dim strFile As String = “”

For Each strFile In files
File.Delete(strFile)
Next

Cheers!

.: Adam


One Response to “ASP.NET File.Delete with a Wildcard”

Leave a Reply