试试这个API:
SearchTreeForFile
极速搜索单个文件,极好的!
VB6代码
模块:
PublicDeclareFunctionSearchTreeForFileLib"imagehlp.dll"(ByVallpRoothPathAsString,ByVallpInputNameAsString,ByVallpOutputNameAsString)AsLong
PublicFunctionsysFileFind(ByValWhichRootPathAsString,ByValWhichFileNameAsString)AsString
DimiNullAsInteger
DimlResultAsLong
DimsBufferAsString
OnErrorGoToL_FILEFINDERROR
sBuffer=String$(1024,0)
lResult=SearchTreeForFile(WhichRootPath,WhichFileName,sBuffer)
IflResultThen
iNull=InStr(sBuffer,vbNullChar)
IfNotiNullThen
sBuffer=Left$(sBuffer,iNull-1)
EndIf
sysFileFind=sBuffer
Else
sysFileFind=""
EndIf
ExitFunction
L_FILEFINDERROR:
MsgBox"查找文件过程中遇到错误!",vbInformation,"查找文件错误"
sysFileFind=Format(Err.Number)&"-"&Err.Description
EndFunction
窗体中的调用:
PrivateSubForm_Load()
Debug.PrintNow,sysFileFind("C:\","VB.EXE")
EndSub |