VB判断指定文件是否存在

Eddy 发布于2009-12-5 0:29:16 分类: 程序设计 已浏览loading 网友评论0条 我要评论

函数代码:

Function DoesFileExist(FilePath As String, Optional FileAttr As VbFileAttribute) As Boolean
If Len(Dir$(FilePath, FileAttr)) > 0 Then
    DoesFileExist = True
Else
    DoesFileExist = False
End If
End Function

一些补充:

Dir函数
返回一个 String,用以表示一个文件名、目录名或文件夹名称,它必须与指定的模式或文件属性、或磁盘卷标相匹配。

语法
Dir[(pathname[, attributes])]

Dir 会返回匹配 pathname 的第一个文件名。若想得到其它匹配 pathname 的文件名,再一次调用 Dir,且不要使用参数。如果已没有合乎条件的文件,则 Dir 会返回一个零长度字符串 ("")。

VbFileAttribute

The VbFileAttribute enumeration contains constants used to identify file attributes used in the Dir, GetAttr, and SetAttr functions.

函数参数可选用Optional关键字

已经有(0)位网友发表了评论,你也评一评吧!
原创文章如转载,请注明:转载自Eddy Blog
原文地址:http://www.rrgod.com/program/194.html     欢迎订阅Eddy Blog

记住我的信息,下次不用再输入 欢迎给Eddy Blog留言