Dir(filename)<>"" then 文件存在

解决方案 »

  1.   

    dim filename as string
    filename="c:\aaa.txt"
    if dir (filename)="" then
    msgbox "文件不存在"
    end if
      

  2.   

    通用函数:Function FileExists(path$) As Boolean
        Dim X
        X = FreeFile ''''get free file #    On Error Resume Next
        Open path$ For Input As X
        If Err = 0 Then
            FileExists = True
        Else
            FileExists = False
        End If
        
        Close XEnd Function
      

  3.   

    If Dir("C:\BOOTLOG.txt", vbHidden Or vbArchive Or vbReadOnly Or vbSystem) = "" Then
    还得考虑到隐藏文件。
      

  4.   

     dim Fname as string
     Fname="Filename"
     if Fname="" then
      msgbox "No Files!","Error!","vbokonly"
     ned fi