怎样判断当前文件夹下是否有指定文件?
或者说,如何判断打开文件成功还是失败??
求源码!

解决方案 »

  1.   

    if dir("路径+文件名")<>"" then 
        msgbox "存在文件"
    endif
      

  2.   

    '*********************************************************
    '* 名称:FileExists%(filename$)
    '* 功能:此函数用于判断文件是否存在
    '* 用法:FileExists%('文件名称')
    '* 文件不存在返回 0
    '*********************************************************
    Function FileExists%(filename$)
        Dim F%
        
        On Error Resume Next
        
        F% = FreeFile
        Open filename$ For Input As #F%
        Close #F%
        
        FileExists% = Not (Err <> 0)
    End Function
      

  3.   

    if dir(App.Path + "test.txt")<>"" then 
        '存在文件
    end if或者使用
    Dim fso As New FileSystemObjectIf fso.FileExists(App.Path + "test.txt") Then
        '存在文件
    end if需要在 引用中加入:microsoft scripting runtime