Skip to main content

Folder.IsRootFolder property

Table of contents
  1. Syntax
  2. Examples

Returns True if the specified folder is the root folder; False if it is not.

Syntax

object.IsRootFolder

The object is always a Folder object.

Examples

The following code illustrates the use of the IsRootFolder property.

Sub DisplayLevelDepth(pathspec)
    Dim fso, f, n
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set f = fso.GetFolder(pathspec)
    If f.IsRootFolder Then
        MsgBox "The specified folder is the root folder."
    Else
        Do Until f.IsRootFolder
            Set f = f.ParentFolder
            n = n + 1
        Loop
        MsgBox "The specified folder is nested " & n & " levels deep."
    End If
End Sub

Run the following code in the Immediate Window to test this macro:

DisplayLevelDepth("d:\TestFolder")

Result:

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>