Skip to main content

Size property

Table of contents
  1. Syntax
  2. Examples

For files, returns the size, in bytes, of the specified file. For folders, returns the size, in bytes, of all files and subfolders contained in the folder.

Syntax

object.Size

The object is always a File or Folder object.

Examples

The following code illustrates the use of the Size property with a Folder object.

Function ShowFolderSize(filespec)
    Dim fs, f, s
    Set fs = CreateObject("Scripting.FileSystemObject")
    Set f = fs.GetFolder(filespec)
    s = UCase(f.Name) & " uses " & f.Size & " bytes."
    MsgBox s, 0, "Folder Size Info"
    Debug.Print s
End Function

Run this code in Immediate Window:

Debug.Print ShowFolderSize("D:\Download")

Result:

DOWNLOAD uses 103899285786 bytes.

Leave a comment

Your email address will not be published. Required fields are marked *

Format your code: <pre><code class="language-vba">place your code here</code></pre>