How to search

Posted on 2004-11-19
Last Modified: 2010-04-23
I am using VB 2003, and am wondering how you make it perform a search. Like say I want to make a program to search for explorer.exe how would I do this?
Question by:tenchi86
    LVL 19

    Accepted Solution

    You mean search for a particular File in the System ???

    You need to recursively search all the Drives/Folders/Sub-Folders
    Or if you want access to some system files like explorer.exe which you know are in a particular path you can directly access

    here's a code for recursive searching

       Public Sub ProcessDirectory(ByVal targetDirectory As String)
            Dim fileEntries As String() = Directory.GetFiles(targetDirectory)
            Dim fileName As String
            For Each fileName In fileEntries
                If fileName.ToUpper = "EXPLORER.EXE" Then
                    Exit Sub
                End If
            Next fileName
            Dim subdirectoryEntries As String() = Directory.GetDirectories(targetDirectory)
            Dim subdirectory As String
            For Each subdirectory In subdirectoryEntries
            Next subdirectory
        End Sub

    call it like ProcessDirectory("C:\")

    Author Comment

    Thanks I will try this later it seems to be what I needed though. Also yes pretty much I just wanted to make vb go into say my computer/C:/programs and find what file I tell it to find.

    Author Comment

    Sorry, for asking this but im a complete noob to this. When I try and run this it pretty much says cannot run debug file not found. So I am screwing up some wheres just not sure where. Also say I wanted it to find say just the winamp file and not winamp.exe do I just replace winamp.exe with winamp?

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Do You Know the 4 Main Threat Actor Types?

    Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

    Article by: jpaulino
    XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String ( Literal, only instead of starting and ending with w…
    Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
    Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
    Internet Business Fax to Email Made Easy - With eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    12 Experts available now in Live!

    Get 1:1 Help Now