I got this from
Dim TheFileName As String
TheFilename = sysFileFind("C", "NWIND.MDB"
If Len(TheFileName) > 0 Then
MsgBox "NWIND.MDB exists: " & TheFileName
Else
MsgBox "NWIND.MDB was not found on drive C"
End if
Should you have knowledge of the folder where NWIND.MDB is supposed to be located, you could use sysFileFind to scan that folder and any of its subfolders. For example:
Dim TheFileName As String
TheFilename = sysFileFind("C:\Program Files", "NWIND.MDB"
If Len(TheFileName) > 0 Then
MsgBox "NWIND.MDB exists: " & TheFileName
Else
MsgBox "NWIND.MDB was not found in C:\Program Files or any of its subfolders."
End if
Declare
Public Declare Function SearchTreeForFile Lib "imagehlp.dll" (ByVal lpRoothPath As String, ByVal lpInputName As String, ByVal lpOutputName As String) As Long
Public Function sysFileFind(ByVal WhichRootPath As String, ByVal WhichFileName As String) As String
Code
Dim iNull As Integer
Dim lResult As Long
Dim sBuffer As String
'internal error handler
On Error GoTo L_FILEFINDERROR
'allocate buffer
sBuffer = String$(1024, 0)
'find file
lResult = SearchTreeForFile(WhichRootPath, WhichFileName, sBuffer)
'if file was found, trim to null
'and return fully qualified path,
'otherwise return zero length string
If lResult Then
iNull = InStr(sBuffer, vbNullChar)
If Not iNull Then
sBuffer = Left$(sBuffer, iNull - 1)
End If
sysFileFind = sBuffer
Else
sysFileFind = ""
End If
Exit Function
L_FILEFINDERROR:
'on error, returns string containing error number and description
MsgBox "Function sysFilefind has returned error code.", vbInformation, "sysFileFind::violation"
sysFileFind = Format(Err.Number) & " - " & Err.Description
End Function
Tip Submitted By: Giorgio Vidali