Applecore Pages on Microsoft Access

How to Find a File on the Computer

If you wish to find the full path to a file on the computer, you can use the FileScriptingObject if you set a reference to it. Alternatively, you can use an API call which will return the first file that matches.

Private Declare Function apiSearchTreeForFile Lib "imagehlp" Alias "SearchTreeForFile" _
    (ByVal RootPath As String, _
    ByVal InputPathName As String, _
    ByVal OutputBuffer As String) As Long
 
Private Const MAX_PATH = 260
 
Function fFindFile(strFile As String, Optional varPath As Variant) As String
'   Function to return the location of a file, given the name of it, searching a maximum depth of 32 directories
'   Accepts:
'       strFile - The name of the file to be found
'       varPath (Optional) - the path to start searching for the file.
'   Returns:
'       The full path and name of the file if it is found, or "" if not found

    Dim strReturn As String
    Dim lngReturn As Long
    If IsMissing(varPath) Then varPath = "C:\"
    strReturn = String(MAX_PATH, 0)
    lngReturn = apiSearchTreeForFile(varPath, strFile, strReturn)
    If lngReturn <> 0 Then
        fFindFile = Left(strReturn, InStr(strReturn, Chr(0)) - 1)
    End If
End Function

Top

 


HOME | NEW | TABLES | QUERIES | FORMS | REPORTS | GENERAL | API | DOWNLOADS | TUTORIAL | RESOURCES
E-MAIL
Copyright & Disclaimer

 

Last modified at 06/06/2006 14:53:13