Private Function folderlist(pathname As String, treeflag As Integer) 'treeflag:0列表 1树形 2树形展开
'文件夹数和名称
Dim sf As String
sf = Dir(pathname, vbDirectory) '获取第一个目录名
foldernum = 0
Do While sf <> ""
' 跳过当前的目录及上层目录
If sf <> "." And sf <> ".." Then
If (GetAttr(pathname + sf) And vbDirectory) = vbDirectory Then
If treeflag = 0 Then
Text2 = Text2 & sf & vbCrLf ' 如果它是一个目录,将其名称添加到列表
ElseIf treeflag = 1 Then
Text2 = Text2 & Treestr & sf & vbCrLf
ElseIf treeflag = 2 Then '树形展开的时候,需要了解子目录,所以还需进行递归调用
Text2 = Text2 & Treestr & sf & vbCrLf
folderlist pathname + sf, treeflag
filelist pathname + sf, treeflag
End If
foldernum = foldernum + 1 '统计文件夹数目
End If
End If
sf = Dir() ' 查找下一个目录
Loop
If treeflag = 0 Then
If foldernum <> 0 Then
Text2 = Text2 & vbCrLf & "======共有" & foldernum & "个文件夹======" & vbCrLf & vbCrLf
Else
Text2 = Text2 & "======无子目录======" & vbCrLf & vbCrLf
End 数返If
ElseIf foldernum <> 0 Then
Text2 = Text2 & Nullstr & vbCrLf & Nullstr & vbCrLf
End If
End Function
Private Function filelist(pathname As String, treeflag As Integer) '0列表 1树形 2树形展开
'文件数和名称
Dim a As String
a = Dir(pathname & "\*.*")
filenum = 0
Do While a <> ""
If treeflag = 0 Then
嫌中 Text2 = Text2 & a & vbCrLf
Else
Text2 = Text2 & Treestr & a & vbCrLf
End If
filenum = filenum + 1 '统计文件数目
a = Dir
Loop
If treeflag = 0 Then
If filenum <> 0 Then
Text2 = Text2 & "======共有" & filenum & "个文件======"
Else
Text2 = Text2 & "======无文件信息======"
End If
End If
End Function
'来个简单的吧Private Sub Command1_Click()
Dim objDlg, objF, DstPath, i
Set objDlg = CreateObject("Shell.Application")
Set objF = objDlg.BrowseForFolder(&H0, "选择存放位置:", &H1)
If InStr(1, TypeName(objF), "Folder", vbTextCompare) >0 Then
DstPath = objF.self.Path
Else
MsgBox "山数目录无效!"
End If
Set objF = Me.Controls.Add("VB.FilelistBox", "picNew", Me)
With objF ' File1
.Pattern = "*.jpg*.bmp*.gif"亮仿
.Path = DstPath
For i = 0 To .ListCount - 1
List1.AddItem DstPath &"\" &.List(i) '假设listbox的名称为list1,敬唯纤请根据实际修改
Next
End With
End Sub
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)