Access开发培训
网站公告
·Access专家课堂QQ群号:151711184    ·Access快速开发平台下载地址及教程    ·欢迎加入Access专家课堂微信群!    ·如何快速搜索本站文章|示例|资料    
您的位置: 首页 > 技术文章 > Access数据库-模块/函数/VBA

【Access函数】FileExists() and FolderExists() 函数

时 间:2012-08-16 10:57:45
作 者:Allen Browne   ID:6392  城市:昆山
摘 要:FileExists() and FolderExists() 函数
正 文:

使用这些功函数来确定是否是一个文件或目录。

使用示例:FileExists("C:\Data\MyFile.mdb")

        FolderExists("C:\Windows\System")

函数代码如下:

Function FileExists(ByVal strFile As String, Optional bFindFolders As Boolean) As Boolean    
 '   如果文件(或隐藏文件)存在则返回真。
                 Dim lngAttributes As Long         
 lngAttributes = (vbReadOnly or vbHidden or vbSystem)     
 If bFindFolders Then         
lngAttributes = (lngAttributes or vbDirectory)     
 Else                
 Do While Right$(strFile, 1) = "\"         
    strFile = Left$(strFile, Len(strFile) - 1)      
   Loop   
  End If   
   On Error Resume Next    
 FileExists = (Len(Dir(strFile, lngAttributes)) > 0) End Function  
 
Function FolderExists(strPath As String) As Boolean  
   On Error Resume Next   
  FolderExists = ((GetAttr(strPath) And vbDirectory) = vbDirectory)
 End Function  
Function TrailingSlash(varIn As Variant) As String    
 If Len(varIn) > 0 Then     
    If Right(varIn, 1) = "\" Then         
    TrailingSlash = varIn      
   Else            
 TrailingSlash = varIn & "\"      
   End If     
End If 
End Function


Access软件网官方交流QQ群 (群号:483923997)       Access源码网店

常见问答:

技术分类:

相关资源:

专栏作家

关于我们 | 服务条款 | 在线投稿 | 友情链接 | 网站统计 | 网站帮助