Skip to main content

FileSystemObject.GetFolder method

Table of contents
  1. Syntax
  2. Remarks
  3. Examples

Returns a Folder object corresponding to the folder in a specified path.

Syntax

object.GetFolder (folderspec)

The GetFolder method syntax has these parts:

Part Description
object Required. Always the name of a FileSystemObject.
folderspec Required. The folderspec is the path (absolute or relative) to a specific folder.

Remarks

An error occurs if the specified folder does not exist.

Examples

The following code illustrates the use of the GetFolder method.

Sub GetFolderDemo()
    Dim fso As Object, f As Object
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set f = fso.GetFolder("D:\Temp\") 'Return the Folder object
    Debug.Print f.DateCreated 'Date when folder was created
    Debug.Print f.Drive 'Result: "D:" - the drive of the folder path
    Debug.Print f.Name 'Result: "Temp" - name of the folder
    Debug.Print f.ParentFolder 'Result: "D:\" - name of the  parent folder
    Debug.Print f.path 'Result: "D:\Temp" - path to the folder
    Debug.Print f.ShortPath 'Returns short path to file with 8.3 naming convention
    Debug.Print f.Size 'Size of folder in bytes
    Debug.Print f.Type 'Result: "File folder"
End Sub

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>