- 10
- 0
- 约4.49千字
- 约 5页
- 2017-06-13 发布于北京
- 举报
VB如何检查文件是否存在?
悬赏分:0 - 解决时间:2007-8-12 19:35
VB如何检查文件是否存在?
比如
要要检查C盘下的1.exe是否存在要用什么么语句
该语句可以加入到
if 这里吗? then
语句
end if
提问者: wulai2761 - 经理 五级 最佳答案
if dir(c:\1.exe,vbHidden+vbReadOnly+vbSystem) then
回答者: 狂族魔帝 - 经理 四级 8-9 15:55
评价已经被关闭 目前有 0 个人评价
好
50% (0) 不好
50% (0)
相关问题
? vb检查文件是否存在
? 如何用VB检查一网上文件是否存在
? 如何用VB检查某一指定文件是否存在呢??
? VB 用什么代码可以检测文件是否存在?
? vb检查文件数量
其他回答 共 2 条
用DIR函数用法如下
Dir[(pathname[, attributes])]
Dir 函数的语法具有以下几个部分:
以 vbDirectory 属性来调用 Dir 不能连续地返回子目录。!!!
以下是VB帮助自带查目录的例子,明确的指出目录必须要用GetAttr!!!
显示 C:\ 目录下的名称。
MyPath = c:\ 指定路径。
MyName = Dir(MyPath, vbDirectory) 找寻第一项。
Do While MyName 开始循环。
跳过当前的目录及上层目录。
If MyName . And MyName .. Then
使用位比较来确定 MyName 代表一目录。
If (GetAttr(MyPath MyName) And vbDirectory) = vbDirectory Then
Debug.Print MyName 如果它是一个目录,将其名称显示出来。
End If
End If
MyName = Dir 查找下一个目录。
Loop
=========================================
(转)
用VB函数Dir实现递归搜索目录
函数GetExtName
功能:得到文件后缀名(扩展名)
输入:文件名
输出:文件后缀名(扩展名)
Public Function GetExtName(strFileName As String) As String
Dim strTmp As String
Dim strByte As String
Dim i As Long
For i = Len(strFileName) To 1 Step -1
strByte = Mid(strFileName, i, 1)
If strByte . Then
strTmp = strByte + strTmp
Else
Exit For
End If
Next i
GetExtName = strTmp
End Function
Public Function search(ByVal strPath As String, Optional strSearch As String = ) As Boolean
Dim strFileDir() As String
Dim strFile As String
Dim i As Long
Dim lDirCount As Long
On Error GoTo MyErr
If Right(strPath, 1) \ Then strPath = strPath + \
strFile = Dir(strPath, vbDirectory Or vbHidden Or vbNormal Or vbReadOnly)
While strFile 搜索当前目录
DoEvents
If (GetAttr(strPath + strFile) And vbDirectory) = vbDirectory Then 如果找到的是目录
If strFile . And strFile .. Then 排除掉父目录(..)和当前目录(.)
lDirCount = lDirCount + 1 将目录数增1
ReDim Preserve strFileDir(lDirCount) As String
strFileDir(lDirCount - 1) = strFile 用动态数组保存当前目录名
End If
Else
If strSearch = Then
Form1.List1.AddItem strPath +
您可能关注的文档
最近下载
- 核医学教学课件:血液和淋巴显像.ppt VIP
- 重庆市各地方周氏支族源流(1-170支族).doc VIP
- 建筑工程质量管理体系流程图.docx
- 淋巴系统核医学检查课件.ppt VIP
- (高清版)B-T 6003.1-2022 试验筛 技术要求和检验 第1部分:金属丝编织网试验筛.pdf VIP
- (已压缩)TUCST007-2020房屋建筑与市政基础设施工程施工安全风险评估技术标准.docx VIP
- 2026年国家公务员考试申论真题及参考答案(考生回忆版).docx VIP
- 部编版语文二年级上册期中常考七大重点题型专项训练.docx VIP
- 机器人操作系统(ROS)及仿真应用 课件全套 第1--9章 Linux Ubuntu入门基础--- 基于ROS的服务机器人应用实例.ppt
- 压疮的预防及护理技术操作考核评分标准编辑.docx VIP
原创力文档

文档评论(0)