SearchFileOnPath – Search a file on system path

SearchFileOnPath – Search a file on system path

Private 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' Search a file on the system' returns the complete file path+name, or "" if file not found'' If SearchDirs is omitted, then the file is searched' in the following directories, in this order'   1. the directory from where the app loaded'   2. the current directory'   3. the WindowsSystem32 directory (if under WinNT)'   4. the WindowsSystem directory'   5. the Windows directory'   6. the directories listed in the PATH environment variableFunction SearchFileOnPath(ByVal FileName As String, _    Optional SearchDirs As String) As String    Dim buffer As String * 260    Dim length As Long    Dim sDirs As String        ' if 2nd argument is omitted, leave sDirs = vbNullString    If Len(SearchDirs) Then sDirs = SearchDirs        length = SearchPath(sDirs, FileName, vbNullString, Len(buffer), buffer, _        vbNullString)    SearchFileOnPath = Left$(buffer, length)End Function


About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist