Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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:

VB
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.
Posted
Updated 10-Nov-10 22:10pm
v4
Comments
Dalek Dave 11-Nov-10 4:04am    
Edited for Grammar, Readability and Code Blocks.

1 solution

Yes, it (of course) is possible.
Checkout the CheckedListBox[^] documentation for implementation details.
:)
 
Share this answer
 
Comments
Dale 2012 11-Nov-10 21:40pm    
Ok but I need some help with this. Checkout the documentation is not the answer im looking for because in my case I have code that I need to perform two areas. Your short answer would only describe one area of my problem and honestly does not help with anything else. Im looking for some professional help with this problem and not a cheeky answer. :)
CPallini 12-Nov-10 7:52am    
Thank you for the vote. Now, I suppose there's nothing more I could do for you.
BTW It wasn't a cheeky answer (and yours isn't a daunting task: waht are your troubles about? I really think you just need to check out the documentation for the technical details about CheckedListBox).
Good luck.
Dale 2012 17-Nov-10 3:29am    
I have asked the question about how to make this code find and when finished delete properly. That is the question but if you cannot do this then I am sorry to have posted anything that may have offended you its just that I was quite frustrated to wait all day for an answer to only find a quick note to go look for more info which I could do without someone telling me to.
CPallini 17-Nov-10 3:40am    
I really (believe me) can't understand what your trouble is. You've proven (with the above code) you can smoothly accomplish the task, after all you've just: (1), add files to the listbox wihtout prompting. (2) Do another iteration on checkbox items, deleting the checked ones. What is the problem, then?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900