Click here to Skip to main content
15,881,599 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Well here goes........ All week I have been trying to figure out recrusion to search all folders and subfolders to no luck do I fully understand it so I asked a few questions here and got the responce that I can use the get files method to search an entire dir such a C:\ for the file im looking for. the problem here is my ignorance to details....... I need to know where to place this code so that it will allow the user to select a root dir from a combobox like c,d,e,f ect and then press start to check the computer for names listed in a text file......MY GOD SOMEONE PUT AN END TO MY SUFFERING!! :(

the code I have is from the MSDN website

VB
Imports System
Imports System.IO
Imports System.Collections

Public Class form1


    ' For Directory.GetFiles and Directory.GetDirectories
    ' For File.Exists, Directory.Exists

    Public Overloads Shared Sub Main(ByVal args() As String)
        Dim path As String
        For Each path In args
            If File.Exists(path) Then
                ' This path is a file.
                ProcessFile(path)
            Else
                If Directory.Exists(path) Then
                    ' This path is a directory.
                    ProcessDirectory(path)
                Else
                    Console.WriteLine("{0} is not a valid file or directory.", path)
                End If
            End If
        Next path
    End Sub 'Main


    ' Process all files in the directory passed in, recurs on any directories
    ' that are found, and process the files they contain.
    Public Shared Sub ProcessDirectory(ByVal targetDirectory As String)
        Dim fileEntries As String() = Directory.GetFiles(targetDirectory)
        ' Process the list of files found in the directory.
        Dim fileName As String
        For Each fileName In fileEntries
            ProcessFile(fileName)

        Next fileName
        Dim subdirectoryEntries As String() = Directory.GetDirectories(targetDirectory)
        ' Recurs into subdirectories of this directory.
        Dim subdirectory As String
        For Each subdirectory In subdirectoryEntries
            ProcessDirectory(subdirectory)
        Next subdirectory

    End Sub 'ProcessDirectory

    ' Insert logic for processing found files here.
    Public Shared Sub ProcessFile(ByVal path As String)
        Console.WriteLine("Processed file '{0}'.", path)
    End Sub 'ProcessFile
End Class 'RecursiveFileProcessor



but how do i make this work with the following

3.buttons of your choice perferably start stop and delete
1.combobox checkbox from devexpress
1 or 2 text or list boxes

anything else?

please please give me something to work with so I can move on from this nightmare

thanks again people.....


I think I need to re phrase my question the best i can

1) the user selects a root dir in the combobox (example....C:\)
2) the text file with the virus names is loaded into a textbox for the user to see
3) start scan is enabled and the search goes into every folder in the root dir untill the text file is done
4) the matched search results from the text file are shown in a text or listbox for the user to review and delete - Dale Seeley 3 mins ago
Posted
Updated 17-Oct-10 22:57pm
v3
Comments
Dalek Dave 18-Oct-10 4:46am    
I can see the sheer honesty of your desperation! :)
[no name] 18-Oct-10 4:51am    
as can i. :/

point 1.
3 buttons,
for this i'd use Asyncronous methods, as you can stop them executing when their not finished, plus they'l not hang up your code - its quite easy to use em - http://www.google.com/url?url=http://www.codeproject.com/KB/cs/AsyncMethodInvocation.aspx&rct=j&sa=U&ei=4gq8TP7nBsH88Abk75HuDg&ved=0CBUQFjAA&q=asynchronous+methods+c%23&usg=AFQjCNFwjmvXcH5684HLzc514ge2eWt10w&cad=rj[^]

start would be beginInvoke(svc.searchMethodName), Stop would be svc.Abort(), and delete? for files? need to import system.IO and use File.Delete whenever the file itself is returned back.

the combobox? i dont undertstand if this is what you want, but if you import (using system.Environment) you can use a method called "GetLogicalDrives()" - then add the returned array to your combobox.
or the list box, maybe to show all the search results? listbox1.items.add(ProcessDirectory(Combobox1.SelectedItem.Text));


Uhm, hope you got all that.. not sure if it'l help much but hopefully get you on the right direction..
 
Share this answer
 
Comments
Dale 2012 18-Oct-10 5:10am    
I think I need to re phrase my question the best i can

1) the user selects a root dir in the combobox (example....C:\)
2) the text file with the virus names is loaded into a textbox for the user to see
3) start scan is enabled and the search goes into every folder in the root dir untill the text file is done
4) the matched search results from the text file are shown in a text or listbox for the user to review and delete
This link has an example that is somewhat bigger, but because you could like to support "stop" during the search you would need to use a thread. Otherwise the UI won't be responsive and the user would have to wait until the operation is completed.

This example on background threads shows how to implement this, using a file search as task. This is just the task you would like to have, so it's a perfect match.

http://msdn.microsoft.com/en-us/library/3s8xdz5c[^]

Good luck!
 
Share this answer
 
Comments
E.F. Nijboer 18-Oct-10 5:01am    
For folder selection you could also use the "FolderBrowserDialog".
Dale 2012 18-Oct-10 5:31am    
well I suppose I could but this is a definition virus scanner and if their are any ways to use a combobox to select a root directory for the names in a text file I would be very greatfull for your advice
Dale 2012 18-Oct-10 5:32am    
what i mean to ask is

I need the user to be able to search the entire root dir when the user selects it from the combobox
the program then uses the text file loaded with the names of the virus to check all areas or subfolders of the root directory.......
E.F. Nijboer 18-Oct-10 12:11pm    
Look at these link with an example of how to get all drives:
http://www.dreamincode.net/code/snippet2041.htm

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