【Access函数】FileExists() and FolderExists() 函数-漏蛧尐魚℡
Access软件网QQ交流学习群(群号码198465573),欢迎您的加入!
首页 >技术文章> Access数据库-模块/函数/VBA


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

发表时间:2012/8/16 10:57:45 评论(1) 浏览(6056)  评论 | 加入收藏 | 复制
   
摘 要: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群(群号:198465573)
 
 相关文章
选择目录的代码  【黄海  2004/11/19】
打开选择目录对话框   【竹笛  2006/4/6】
利用API创建文件目录  【UMVSOFT整理  2008/5/19】
双击打开目录代码  【  2008/7/1】
用VBA代码打开指定的文件夹目录  【竹笛  2008/10/15】
常见问答
技术分类
相关资源
文章搜索
关于作者

漏蛧尐魚℡

文章分类

文章存档

友情链接