CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Feb 2000
    Location
    America
    Posts
    130

    Writing a program like window's "Find"

    I need to make my program search the computer for sertain files with sertain specifics. Can someone tell me the basic idea of how to do this? The only hard part I'm having with it is I don't know how to check each and every single folder and subfolder.


  2. #2
    Join Date
    Sep 1999
    Posts
    17

    Re: Writing a program like window's "Find"

    I copied that peace of code from another vb-forum, but I forgot from where. It shows you how to search subfolders recursively.


    Check if file exist and when found show the location


    'btw: it will only find the first one!
    'just change the code to find all
    'use as:

    'MsgBox FindFile("c:\", vFile$) & vFile$

    public Function FileExist(Path$) as Integer
    Dim x

    x = FreeFile

    on error resume next
    Open Path$ for input as x
    If Err = 0 then
    FileExist = true
    else
    FileExist = false
    End If
    Close x

    End Function

    public Function FindFile(byval Path as string, byval File as string) as string
    Dim DirName as string, LastDir as string

    If File = "" then Exit Function
    If Right(Path, 1) <> "\" then Path = Path & "\"

    DirName = Dir(Path & "*.*", vbDirectory)
    Do While Not FileExist(Path & File)

    If DirName = "" then Exit Do
    DoEvents
    If DirName <> "." And DirName <> ".." then
    If (GetAttr(Path & DirName) And vbDirectory) = vbDirectory then
    LastDir = DirName
    DirName = FindFile(Path & DirName & "\", File)
    If DirName <> "" then
    Path = DirName
    Exit Do
    End If
    DirName = Dir(Path, vbDirectory)
    Do Until DirName = LastDir Or DirName = ""
    DirName = Dir
    Loop
    If DirName = "" then Exit Do
    End If
    End If
    DirName = Dir
    Loop

    If FileExist(Path & File) then FindFile = Path

    End Function







Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured