I have posted this question now a few times with few answers that have given me any progress in this situation. My program scans for names that are within a text file and if the name in the text file is found the result then becomes a item in my checklistbox. The problem is that my code only removes the item and not the actual file in my computer.
my code is as follows:
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
For i As Integer = CheckedListBox1.CheckedItems.Count - 1 To 0 Step -1
red = Replace(CheckedListBox1.CheckedItems.Item(i).ToString(),"Threat Found: ","")
Try
System.IO.File.Delete(red)
If Dir(red) <> "" Then
MsgBox("Unable to delete" & red, MsgBoxStyle.Critical)
Else
MsgBox(String.Format("File {0} successfully deleted", red), MsgBoxStyle.Information)
CheckedListBox1.Items.Remove(CheckedListBox1.CheckedItems)
End If
Catch ex As Exception
End Try
Next
end sub
Again I have had someone say that I should see if the file exists by saying System.io.file.exists(red) and then going onto system.io.file.delete(red) and if true to delete or show a msgbox error.
This is a good idea and I have tried to change the code to this.....
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
For i As Integer = CheckedListBox1.CheckedItems.Count - 1 To 0 Step -1
red = Replace(CheckedListBox1.CheckedItems.Item(i).ToString(), "Threat Found: ","")
If System.IO.File.Exists(red) Then
System.IO.File.Delete(red)
ElseIf Dir(red) <> "" Then
MsgBox("Unable to delete" & red, MsgBoxStyle.Critical)
Else
CheckedListBox1.Items.Remove(CheckedListBox1.CheckedItem(0)) MsgBox(String.Format("File {0} successfully deleted", red), MsgBoxStyle.Information)
End If
Next
End Sub
This still only does what the first example does and truly I am out of ideas or thoughts of why the file is still not being deleted. Will someone please review this code and possibly give his or her rewritten code to perform the file delete successfully as I have been trying for about a week with more than 3 questions not fully answered.
Thank you for trying to help I appriciate whatever help you give in this issue.....