vb查找文件 模组出错问题 那位高手帮忙看看吧

2025-02-22 11:39:12
推荐回答(3个)
回答1:

'这样可以了:

Private Declare Function SearchTreeForFile Lib "imagehlp.dll" (ByVal lpRoothPath As String, ByVal lpInputName As String, ByVal lpOutputName As String) As Long
Private Declare Function GetLogicalDriveStrings Lib "kernel32" Alias "GetLogicalDriveStringsA" (ByVal nBufferLength As Long, ByVal lpBuffer As String) As Long
Private Declare Function GetDriveType Lib "kernel32" Alias "GetDriveTypeA" (ByVal nDrive As String) As Long

Public Function getDirList() As String() 'μ?μ?ó2?ìáD±í£???±ê0?aê?
Dim tmp As String * 64
GetLogicalDriveStrings Len(tmp), tmp 'μ?μ??ùóDía′??ì·?áD±í

DirList = Split(tmp, Chr(0))
Dim Count As Integer
Count = 1
Dim arr() As String
For i = 0 To UBound(DirList)
Select Case GetDriveType(DirList(i))
Case 2 'Removable
Case 3 'DriveFixed
ReDim Preserve arr(Count) As String
arr(Count) = DirList(i)
Count = Count + 1
Case 4 'Remote
Case 5 'CD-ROM
Case 6 'RAMDisk
Case Else 'Unrecognized
End Select
Next
getDirList = arr
End Function

Public 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 L_FILEFINDERROR
sBuffer = String$(1024, 0)
'×¢êí:2é?ò???t

lResult = SearchTreeForFile(WhichRootPath, WhichFileName, sBuffer)
'×¢êí£o?ùè????t?òμ?£???·μ??×?·?′?oóD?μ?????é?3y
'×¢êí:·??ò·μ??ò?????×?·?′?
If lResult Then
iNull = InStr(sBuffer, vbNullChar)
If Not iNull Then
sBuffer = Left$(sBuffer, iNull - 1)
End If
sysFileFind = sBuffer
Else
sysFileFind = ""
End If
Exit Function
L_FILEFINDERROR:
MsgBox "2é?ò???t1y3ì?D??μ?′í?ó£?", vbInformation, "2é?ò???t′í?ó", sysFileFind = Format(Err.Number) & "-" & Err.Description

End Function

Function allSearch(FileName As String) As String
arr = getDirList() 'μ?μ?ó2?ìáD±í
allSearch = ""
For i = 1 To UBound(arr)
allSearch = sysFileFind(arr(i), FileName)
If Len(allSearch) > 0 Then
Exit For
End If
Next
End Function

回答2:

说一下出错的行,省得看半天

回答3:

您可以下载一个文件,本人早已下载,对英语感兴趣。