Searching for a file path on the users computer

  • Thread starter Thread starter Mota
  • Start date Start date
M

Mota

Hi;
Can i search for a specific file on the user PC (i.e. "Dialer.EXE" or
"WinFaxMng32.EXE"),and know its full path,if it exist?
Thank you so much.
 
Hi,
Here's one way to do it without writing a lot of code.
The only drawback is you have to pass it a path that tells it where to
start the search. You can simply pass it C:\, but if there are other drives
it won't search them.

Put this code in a standard module in the declarations section:

Public Const MAX_PATH = 260

Public Declare Function SearchTreeForFile Lib "imagehlp" _
(ByVal RootPath As String, ByVal InputPathName As String, ByVal OutputPathBuffer As String) As Long


The code to call it can be put anywhere you like:

Dim tempStr As String
Dim Ret As Long
'create a buffer string
tempStr = String(MAX_PATH, 0)
'returns 1 when successfull, 0 when failed
Ret = SearchTreeForFile("c:\", "Dialer.EXE", tempStr)
If Ret <> 0 Then
MsgBox "Located file at " + Left$(tempStr, InStr(1, tempStr, Chr$(0)) - 1)
Else
MsgBox "File not found!"
End If

End Sub

Be aware that the search will take a while, so be patient and wait for the MsgBox
 
Thank you so much;
may i use it in a loop to check all drives?
In this case i need an API that returns all drive letters,and i have forgot
it.Do u remember this API?
Thanx.

Dan Artuso said:
Hi,
Here's one way to do it without writing a lot of code.
The only drawback is you have to pass it a path that tells it where to
start the search. You can simply pass it C:\, but if there are other drives
it won't search them.

Put this code in a standard module in the declarations section:

Public Const MAX_PATH = 260

Public Declare Function SearchTreeForFile Lib "imagehlp" _
(ByVal RootPath As String, ByVal InputPathName As String, ByVal
OutputPathBuffer As String) As Long
 
Back
Top