FolderExistsメソッド

指定されたフォルダが存在する場合はTrue、存在しない場合はFalseを戻します。

構文

object.FolderExists(folderspec)

引数:

  • Object: 必須。常にFileSystemObjectの名前。
  • Folderspec: 必須。存在を判別するフォルダの絶対パス。

次の例では、FileExistsメソッドの使用方法を示します。

例1:

Function CheckFolderExistence(fldr)
    Dim fso, msg
    Set fso = CreateObject("Scripting.FileSystemObject")

    If fso.FolderExists(fldr) Then
        msg = fldr & " exists."
    Else
        msg = fldr & " doesn't exist."
    End If

    CheckFolderExistence = msg
End Function

' Usage
Dim folderPath
folderPath = "C:\1"
bExists = CheckFolderExistence(folderPath)
'bExists now holds C:\1 exists. if the folder exists, else It will have C:\1 doesn’t exists.