2,462
社区成员
发帖
与我相关
我的任务
分享
Sub test4()
'另外的一种FSO方法。
Dim fso As New FileSystemObject
Dim flds As Folders
Dim strText As String
Dim i As Integer
Set flds = fso.GetFolder("C:\").SubFolders
i = 1
'在excel里面显示c盘的子文件夹。只有一层。要多层,自己调用嵌套函数。
For Each f In flds
strText = f.Path & " - " & f.Size
Worksheets("Sheet1").Cells(i, 1) = strText
i = i + 1
Next
End Sub
Sub test5()
Dim fso As New FileSystemObject
Dim fls As Files
Dim strText As String
Dim i As Integer
Set fls = fso.GetFolder("C:\Windows\system").Files
'显示 所有文件。配合上面的函数,应该可以写出来了吧。
i = 2
With Worksheets("Sheet1")
.Cells(1, 1) = "File Name"
.Cells(1, 2) = "File Size"
.Cells(1, 3) = "Date"
For Each f In fls
.Cells(i, 1) = f.Name
.Cells(i, 2) = f.Size
.Cells(i, 3) = f.DateLastModified
i = i + 1
Next
End With
End Sub
Set FSO = CreateObject("scripting.filesystemobject")