我在线上获取了代码,以获取文件夹名称和大小
我收到无效的限定词错误@
ThisWorkbook.Sheets(1).Cells(i, 1) = Folder - Name.Name
Sub GetFolderSizeDetails()
Dim FSO As FileSystemObject
Dim FolderName As Folder
'Assign path of folder for which you want it's sub folder list and size
RootPath = "C:\"
ThisWorkbook.Sheets(1).Range("A2:D100").ClearContents
'Initialize Variables And Objects
i = 1
Set FSO = New FileSystemObject
'Loop to get each Subfolder in the Root Path
For Each FolderName In FSO.GetFolder(RootPath).SubFolders
i = i + 1
ThisWorkbook.Sheets(1).Cells(i, 1) = Folder - Name.Name
On Error Resume Next
'Folder-Name.Size returns value in Bytes. Thus divided by 1024 to convert in MB
ThisWorkbook.Sheets(1).Cells(i, 2) = (Folder - Name.Size / 1024) / 1024
Next
MsgBox "All folders listed with their size"
End Sub