Results 1 to 3 of 3

Thread: searchpath API call

  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 2001
    Posts
    3
    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

  2. #2
    New Member
    Join Date
    Sep 2008
    Posts
    1

    Cool Re: searchpath API call

    Try:
    Code:
        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)

  3. #3
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: searchpath API call

    To use null string values, recommend passing vbNullString, not ""
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

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