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.