回复 楼主 bestsunshine
界面添加一个ListView1和一个Command1
程序代码:
Option Explicit
Private Sub Command1_Click()
Dim ObjFileSystem As New FileSystemObject '需引用Microsoft Scripting Runtime
Dim ObjFolder As Folder '文件夹
Dim ObjFile() As File '文件
Dim FileTotal As Integer '文件总数
Dim i As Integer
Set ObjFolder = ObjFileSystem.GetFolder("D:\anyTest\") ''
Dim tempFile As File
FileTotal = 0
For Each tempFile In ObjFolder.Files ''遍历文件夹中所有文件
FileTotal = FileTotal + 1
ReDim Preserve ObjFile(1 To FileTotal) ''数组长度加1,且保留原内容
Set ObjFile(FileTotal) = tempFile
Next
ListView1.ListItems.Clear '清空列表
ListView1.ColumnHeaders.Clear '清空列表头
ListView1.View = lvwReport '设置列表显示方式
ListView1.GridLines = True '显示网络线
ListView1.LabelEdit = lvwManual '禁止标签编辑
ListView1.FullRowSelect = True '选择整行
ListView1.ColumnHeaders.Add , , "No.", 500
ListView1.ColumnHeaders.Add , , "Name", 4000 'Name
ListView1.ColumnHeaders.Add , , "Size", 1000 'Size
ListView1.ColumnHeaders.Add , , "Type", 3000 'Type
ListView1.ColumnHeaders.Add , , "Date Modified", 3500 'Date Modified
For i = 1 To FileTotal
i = ListView1.ListItems.Count + 1
ListView1.ListItems.Add , , i
ListView1.ListItems(i).SubItems(1) = ObjFile(i).Name
ListView1.ListItems(i).SubItems(2) = Int((ObjFile(i).Size / 1024) + 0.5) & "KB"
ListView1.ListItems(i).SubItems(3) = ObjFile(i).Type
ListView1.ListItems(i).SubItems(4) = ObjFile(i).DateLastModified
Next
End Sub
图片附件: 游客没有浏览图片的权限,请
登录 或
注册