Skip to main content

FileSystemObject.FolderExists method

Table of contents
  1. Syntax
  2. Examples

Returns True if a specified folder exists; False if it does not.

Syntax

object.FolderExists (folderspec)

The FolderExists method syntax has these parts:

Part Description
object Required. Always the name of a FileSystemObject.
folderspec Required. The name of the folder whose existence is to be determined. A complete path specification (either absolute or relative) must be provided if the folder isn't expected to exist in the current folder.

Examples

The following code illustrates how to use the FolderExists method to determine if a folder exists in a directory.

'------------------ Modules ------------------
Sub FileExist()
    Dim objFso As Object
    Dim strPath As String
    strPath = ThisWorkbook.path & Application.PathSeparator
    Set objFso = CreateObject("Scripting.FileSystemObject")
    Debug.Print objFso.FolderExists(strPath & "TestFolder")
    Debug.Print objFso.FileExists(strPath & "TestFile.txt")
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>