Login | Register   
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: VB4/32,VB5,VB6
Expertise: Intermediate
Mar 10, 2001

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 \Windows\System32 directory (if under WinNT)
'   4. the \Windows\System directory
'   5. the \Windows directory
'   6. the directories listed in the PATH environment variable

Function 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
Francesco Balena
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap