PDA

Click to See Complete Forum and Search --> : searchpath API call


dberndt
Feb 18th, 2001, 01:45 AM
Hi
i have recently been righting a highly modified/specialized installer and i need to search the whole path and the windows directories for a file to find out if it exists. So i figure what better way than searchpath.

Declare Function SearchPath Lib "kernel32" Alias "SearchPathA" (ByVal lpPath As String, ByVal lpFileName As String, ByVal lpExtension As String, ByVal nBufferLength As Long, ByVal lpBuffer As String, ByVal lpFilePart As String) As Long

The problem is that either i am not passing it a proper null string for the lpPath or it doesn't work as the msdn says. I can do this
x= SearchPath("","autoexec.bat", "", 0, temp, 0)
and x is always 0
but if i just give it
x= SearchPath("c:\","autoexec.bat", "", 0, temp, 0) it works great. so i suspect that there is something funky happenning when i pass it "" for lpPath.

Any help would be appreciated.

Thanks

David Berndt

krazymike
Apr 25th, 2011, 04:16 PM
Try:

Dim mPath As String * 1024 ' set some value to mPath
Dim mBuffer As Long

' how big buffer do I need
mBuffer = ("c:", "autoexec.bat", ".bat", 0, mPath, 0)
' let's get the path SearchPathif exists
mBuffer = SearchPath("c:\", "autoexec.bat", ".bat", mBuffer, mPath, 0)

Debug.Print Left(mPath, mBuffer)

LaVolpe
Apr 29th, 2011, 08:03 AM
To use null string values, recommend passing vbNullString, not ""