VB 判断当前目录文件是否存在?

比如判断当前目录是否存在名为"abc.txt"的文件,有和没有分别执行不同的分支语句!越简短越好!谢谢

这可用下列语句进行判断 

Dir([pathname],[Attributes as VbFileAttribute=vbNormal]) As String 

解释: pathname:文件的绝对路径; 

Attributes:文件的属性。 

“[]”内为可选项。dir(file)=""表示文件不存在,dir(file)<>""表示文件存在。 

例如判断c:wpswinwps.exe是否存在,如存在,就调用它,可用下列语句: 

if dir("c:wpswinwps.exe")<>"" then 

shell "c:wpswinwps.exe" 

end if 

温馨提示:答案为网友推荐,仅供参考
第1个回答  推荐于2018-02-27
if dir(app.path & "\abc.txt")="" then
'不存在
else
'存在
end if本回答被提问者和网友采纳
第2个回答  2012-03-28
if dir(app.path & "\abc.txt")<>"" then
MsgBox app.path & "\abc.txt")<>"" & "文件存在 "
else
MsgBox app.path & "\abc.txt")<>"" & "文件不存在 "
end if
第3个回答  2012-03-28
dir(你的文件路径)>0 表示文件存在,否则不存在
第4个回答  2012-03-28
Dim fsoTest As New FileSystemObject
If fsoTest.FolderExists(App.Path & "\abc.txt") = True Then
MsgBox "文件存在 "
Else
MsgBox "不存在 "
End If
相似回答