I am trying to place this code to function in two ways.
1) Find the file and add it to my checklistbox.
2) Use a delete button to delete the found file
This is the code id like to split into two sections as stated above:
Function RepeatFiles(ByVal dirs As DirectoryInfo)
Dim fileListing() As FileInfo = dirs.GetFiles()
If fileListing.Length > 0 Then
For Each fl As FileInfo In fileListing
If Button1.Enabled = False Then
currentPath.Text = fl.FullName
Application.DoEvents()
Dim currentFileName As String = fl.Name
Dim fileExists As Boolean = My.Resources.VirusList.Contains (currentFileName)
If fileExists = True Then
If MessageBox.Show("Infection found:" & fl.Name,"Threat Alert!",MessageBoxButtons.YesNo, MessageBoxIcon.Question) = DialogResult.Yes Then
CheckedListBox1.Items.Add(String.Format("Infection Removed:{0}{1}", fl.FullName, fl.Name))
fl.Delete()
End If
End If
End If
Next
End If
Currently this code stops the scan every time a threat is found and asks the user to either delete the file or not.
This can be a bit of a annoyance instead of just adding all the threats to the checklistbox and prompting for action when the scan has completed.
This is what I'd like it to do so that the user can check or uncheck the threats to delete.