怎么判断文件夹或者文件已经存在

penghongjie 2006-03-23 11:39:51
怎么判断文件夹或者文件已经存在?
...全文
153 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
xDAVIDx 2006-03-24
  • 打赏
  • 举报
回复
Dir(文件名),如果返回值为"",则不存在;若不为"",则存在.
yangfengcl 2006-03-24
  • 打赏
  • 举报
回复
第一种
Private fso As New FileSystemObject
If fso.FileExists("c:\wallpaper.jpg") = True Then
Msgbox"文件存在!"
Else
Msgbox"文件不存在!"
Endif

第二种
if dir(文件路径)<>"" then
msgbox"存在"
else
msgbox"不存在"
end if
zpsinz 2006-03-24
  • 打赏
  • 举报
回复
楼上是正解。。
还可以判断文件夹
dim objFSO as new filesystemobject
objfso.floderexists(文件夹绝对路径)
3q2008Com 2006-03-24
  • 打赏
  • 举报
回复
判断文件是否打开
Public Function IsFileOpen(sFile As Variant) As Boolean
Dim fFile As Integer
Dim msg As String
fFile = FreeFile()
On Error GoTo ErrOpen
Open sFile For Binary Lock Read Write As fFile
Close fFile
Exit Function
ErrOpen:

If Err.Number <> 70 Then
msg = "Error # " & Err.Number & " was generated by " _
& Err.Source & Chr(13) & Err.Description
MsgBox msg, , "Error", Err.HelpFile, Err.HelpContext
Else
IsFileOpen = True
End If
End Function


Dogfish 2006-03-24
  • 打赏
  • 举报
回复
FileSystemObject

FS.fileexists(filename) = true or false
yinweihong 2006-03-23
  • 打赏
  • 举报
回复
if DIR(file)
if dir(folder,vbdirectory)
rainstormmaster 2006-03-23
  • 打赏
  • 举报
回复
if dir(文件路径)<>"" then
存在
end if

7,763

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧