《盟威软件快速开发平台》在线帮助中心

PathFileExists 函数

判断指定文件夹或文件是否存在。

语法

PathFileExists (PathFile)

参数

参数名称 必需/可选 数据类型 说明
PathFile 必需 String 文件夹或文件的路径名。

返回值

如果文件夹或文件存在返回True,否则返回False

说明

VBA内置的Dir函数也可以实现判断文件或文件夹是否存在的功能,但是其对于文件和文件夹需要指定不同的额外参数,没有 PathFileExist函数 方便。

如果是判断文件夹,则PathFile参数最后有无路径分隔符(“\”)均视为有效。

原型

Public Function PathFileExists(PathFile As String) As Boolean

相关引用

Win32 API -> shlwapi.dll -> PathFileExistsA函数

示例

Sub Test()
    If PathFileExists("C:\Windows") Then
        MsgBox "C:\Windows 存在"
    End If
    If PathFileExists("C:\Windows\") Then
        MsgBox "C:\Windows\ 存在"
    End If
    If Not PathFileExists("C:\Windows\test.exe") Then
        MsgBox "C:\Windows\test.exe 不存在"
    End If
End Sub