Deleting a File

I am trying to delete a file. This code deletes the listing but not the file


Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
If ListBox3.Items.Count - 1 >= 0 Then
Dim lst As New List(Of Object)
For Each a As Object In ListBox3.SelectedItems
lst.Add(a)
Next
For Each a As Object In lst
ListBox3.Items.Remove(a)
Next

Dim li As Integer

Dim fn As String

For li = ListBox3.SelectedIndices.Count - 1 To 0 Step -1

fn = ListBox3.Items(ListBox3.SelectedIndices(li))

If File.Exists(fn) Then

File.Delete(fn)

End If

ListBox3.Items.RemoveAt(ListBox3.SelectedIndices(li))

Next
MsgBox("Go to threat address location and delete file")
Else : MsgBox("No files to delete")
End If
End Sub

any ideas?
this is not a VBA forum but since you ask for deleting a file here's the C-function for it.
http://www.cplusplus.com/reference/cstdio/remove/
Last edited on
Topic archived. No new replies allowed.