我如何访问一个文件,但不运行这个文件,如果这个文件存在返回1,如果文件不存在返回0.

解决方案 »

  1.   

    dim xPath as string,rtn as long
    xPath=app.path & "fir.txt"
    rtn=dir(xPath)
      

  2.   

    public fuction IsFileExist(cFile as string)as long
           'dim cFile as string
           cFile=c:\app\my.exe
           if dir(cFile)<>"" then
              IsFileExist=1
           else
              IsFileExist=0
           endif
    end function 
      

  3.   

    cFile=c:\app\my.exe可作为参数传入.
      

  4.   

    Private Sub Form_Load()
       MsgBox IIf(Dir("c:\calc.exe") <> "", "存在", "不存在")
    End Sub
    '你的思路调用涵数返回的方式Private Sub Form_Load()
       MsgBox ChkFile("c:\calc.exe")
    End SubPublic Function ChkFile(Exenm$) As Long
       ChkFile = IIf(Dir(Exenm) <> "", 1, 0)
    End Function
      

  5.   

    '如果连隐藏文件也要能找到的话, 改为下面代码Private Sub Form_Load()
       MsgBox ChkFile("c:\calc.exe")
    End SubPublic Function ChkFile(Exenm$) As Long
       ChkFile = IIf(Dir(Exenm, vbHidden) <> "", 1, 0)
    End Function