VB 搜索文件夹

来源:百度知道 编辑:UC知道 时间:2024/06/19 08:21:32
得到一个路径a ( c:\ ),把a中的文件夹全部列出到list1。
分数不重要 要的是速度
已解决。

List1.Clear
On Error Resume Next
Dim strFile As String
strpath = Text1

If Right(strpath, 1) <> "\" Then strpath = strpath + "\"
strFile = Dir(strpath, vbDirectory Or vbHidden Or vbNormal Or vbReadOnly Or vbSystem)
While strFile <> ""
DoEvents
If (GetAttr(strpath + strFile) And vbDirectory) = vbDirectory Then
If strFile <> "." And strFile <> ".." Then List1.AddItem "■ " + strFile
End If
strFile = Dir
Wend

VB搜索文件夹,列出指定文件夹下全部文件夹或全部隐藏的文件夹

'查找第一个文件的API
Private Declare Function FindFirstFile Lib "kernel32" Alias "FindFirstFileA" (ByVal lpFileName As String, lpFindFileData As WIN32_FIND_DATA) As Long
'查找下一个文件的API
Private Declare Function FindNextFile Lib "kernel32" Alias "FindNextFileA" (ByVal hFindFile As Long, lpFindFileData As WIN32_FIND_DATA) As Long
'获取文件属性的API
Private Declare Function GetFileAttributes Lib "kernel32" Alias "GetFileAttributesA" (ByVal lpFileName As String) As Long
'关闭查找文件的API
Private Declare Function FindClose Lib "kernel32" (ByVal hFindFile As Long) As Long

'常量
Private Const MAX_PATH = 260
Private Const MAXDWORD = &HFFFF
Private Const INVALID_HANDLE_VALUE = -1
Private Const FILE_ATTRIBUTE_ARCHIVE = &H20
Private Const FILE_ATTRIBUTE_DIRECTORY = &H10
Private Const FILE_ATTRIBUTE_HIDDEN = &H2