1

I picked up code online, for getting folder names and size

I get Invalid qualifier error @ 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
Community
  • 1
  • 1
  • 2
    Replace the instances of `Folder - Name` with `FolderName`. Looks like a typo, or perhaps whatever site you found it on needs to get its act together. – BigBen Feb 13 '19 at 05:36
  • 1
    Or did someone do a edit:find/replace without thinking of all the consequences? – Solar Mike Feb 13 '19 at 05:59

0 Answers0