Results 1 to 2 of 2

Thread: How to scan for a file.

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Nov 1999
    Posts
    25

    Post

    Can anyone help me with this?

    I want my program to scan and find the computer drives for a certain file.

    If the file is on the computer then I need to load the location into a string.

    Can anyone help me?

    ------------------
    Thanks,
    MiDaWe

  2. #2
    Guru Aaron Young's Avatar
    Join Date
    Jun 1999
    Location
    Red Wing, MN, USA
    Posts
    2,176

    Post

    Try Something Like this:
    Code:
    Private Sub Command1_Click()
        MsgBox FindFile(Text1, "C:\")
    End Sub
    
    Function FindFile(ByVal sFileName As String, Optional ByVal sInitPath As String) As String
        If IsMissing(sInitPath) Then sInitPath = CurDir
        Dim aSubDirs() As String
        Dim iDirs As Long
        Dim sDir As String
        
        If Right$(sInitPath, 1) <> "\" Then sInitPath = sInitPath & "\"
        sDir = Dir(sInitPath & "*", vbDirectory + vbNormal + vbHidden + vbReadOnly + vbSystem)
        While Len(sDir)
            If LCase(sDir) = LCase(sFileName) Then
                FindFile = sInitPath & sDir
                Exit Function
            Else
                If (GetAttr(sInitPath & sDir) And vbDirectory) = vbDirectory And Left$(sDir, 1) <> "." Then
                    ReDim Preserve aSubDirs(iDirs)
                    aSubDirs(iDirs) = sDir
                    iDirs = iDirs + 1
                End If
            End If
            sDir = Dir
        Wend
        
        If iDirs Then
            For iDirs = 0 To UBound(aSubDirs)
                FindFile = FindFile(sFileName, sInitPath & aSubDirs(iDirs))
                If Len(FindFile) Then Exit For
            Next
        End If
    End Function
    ------------------
    Aaron Young
    Analyst Programmer
    aarony@redwingsoftware.com
    adyoung@win.bright.net

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