在VB中如何判断文件、文件夹是否存在和生成文件夹

如题所述

'判断文件
Public Function FileExists(ByVal File As String) As Boolean
On Error Resume Next
If (GetAttr(File) And vbDirectory) = False Then FileExists = True
If err Then FileExists = False: err.Clear
End Function
'判断目录
Function FolderExists(ByVal Folder As String) As Boolean
On Error Resume Next
If GetAttr(Folder) And vbDirectory Then FolderExists = True
If err Then FolderExists = False: err.Clear
End Function

 

 '创建多层目录
Public Declare Function MakeSureDirectoryPathExists Lib "imagehlp.dll" (ByVal DirPath As String) As Long
用法:
MakeSureDirectoryPathExists "c:/this/is/a/test/directory/"
温馨提示:答案为网友推荐,仅供参考
第1个回答  2014-04-23

用dir函数,更喜欢用fso

第2个回答  2014-04-23
API函数:FileExist,可能记错了
第3个回答  2014-04-23
dir(路径)

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网