Form with a single button
Code:
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
RemoveFile("D:\Data", "test.test")
End Sub
End Class
Code Module, replace the console write with your delete method
Code:
Imports System.IO
Module FileCode
Private FileToRemove As String = ""
Public Sub RemoveFile(ByVal FolderName As String, ByVal FileName As String)
FileToRemove = FileName
RecurseDirectory(New DirectoryInfo(FolderName))
End Sub
Public Sub RecurseDirectory(ByVal FolderInfo As DirectoryInfo)
Dim nextDir As DirectoryInfo
WorkFiles(FolderInfo)
For Each nextDir In FolderInfo.GetDirectories
RecurseDirectory(nextDir)
Next
End Sub
Public Sub WorkFiles(ByVal FolderInfo As DirectoryInfo)
Dim FI As FileInfo
For Each FI In FolderInfo.GetFiles()
If IO.Path.GetFileName(FI.FullName.ToLower) = FileToRemove.ToLower Then
Console.WriteLine(FI.FullName)
End If
Next
End Sub
End Module