SearchTreeForFile
SearchTreeForFileVB声明Declare Public Declare Function SearchTreeForFile Lib "imagehlp.dll" (ByVal lpRoothPath As String, ByVal lpInputName As String, ByVal lpOutputName As String) As Long
该函数在imagehlp.dll动态链接库中
说明
寻找文件完整路径
返回值
Long型,如果不存在该文件返回值为0
参考表
lpRoothPath 查找的磁盘路径 即根目录
lpInputName 查找的文件名字
lpOutputName 输出路径缓冲区示例:用于查找F盘中是否存在1.txt这个文件。
Private Declare Function SearchTreeForFile Lib "imagehlp.dll" _
(ByVal lpRoothPath As String, ByVal lpInputName As String, _
ByVal lpOutputName As String) As Long
Private Function sysFileFind(ByVal WhichRootPath As String, ByVal WhichFileName As String) As String
Dim iNull As Integer
Dim lResult As Long
Dim sBuffer As String
On Error GoTo FileFindError
sBuffer = String$(1024, 0)
lResult = SearchTreeForFile(WhichRootPath, WhichFileName, sBuffer)
If lResult Then
iNull = InStr(sBuffer, vbNullChar)
If Not iNull Then
sBuffer = Left$(sBuffer, iNull - 1)
End If
sysFileFind = sBuffer
MsgBox sysFileFind, vbOKOnly, "提示"
Else
MsgBox "F盘中不存在1.txt文件", vbOKOnly, "提示"
End If
Unload Me
Exit Function
FileFindError:
MsgBox "查找文件过程中遇到错误!", vbInformation, "查找文件错误"
Unload Me
End Function
Private Sub Form_Load()
sysFileFind "F:", "1.txt"
End Sub