-2

i'm creating a anti-virus and I'm having a little trouble deleting the viruses. Here is my code:

If threatsLb.Items.Count > 0 Then
    threatsLb.Enabled = True
    Dim KillFile As String
    KillFile = threatsLb.SelectedItem
    If Len(Dir$(KillFile)) > 0 Then
        SetAttr(KillFile, vbNormal)
        Kill(KillFile)
    End If
End If

Basically, if there is a virus then the address of the virus will be stored in a list box. But the 'KillFile = threatsLb.SelectedItem' isn't selecting any of the items in the list box. I know I'm doing something wrong... can you guys help? thanks!

Kirill Kobelev
  • 9,758
  • 6
  • 24
  • 46

1 Answers1

0

That's not really how you remove viruses but here you go.

If threatsLb.Items.Count > 0 Then
   For Each KillFile As String In threatsLb.Items
     If Not KillFile = "" Then
        SetAttr(KillFile, vbNormal)
        IO.File.Delete(KillFile)
     End If
   Next
End If

This will delete every files in your ListBox.

Note that KillFile has to be the location of the file (ex: "C:\myfile.txt")

Sceeker
  • 15
  • 3