如题。

解决方案 »

  1.   

    Private Sub Command1_Click()
    Dim myfile As String
    myfile = Dir("c:\1new.mdb")
    MsgBox myfile
    End Sub看msdn的dir函数
      

  2.   

    或者fsoOption Explicit
    Dim fs As New FileSystemObjectPrivate Sub Command1_Click()
    If fs.FileExists("c:\new.mdb") Then
    MsgBox "存在"
    Else
    MsgBox "不存在"
    End If
    End Sub
      

  3.   

    '检测文件sFilename是否存在
    Public Function FileExists(sFilename As String) As Boolean
        On Error Resume Next
        FileLen sFilename
        FileExists = (Err.Number = 0)
    End Function
      

  4.   

    或者 用文件系统filesystemobject
    MSDN上有详细的例子,一看就知道了,你输入filesystemobject
    就可以看到了
      

  5.   

    if Dir("c:\test.txt")="" then
      msgbox "不存在"
    else
      msgbox "存在"
    end if
      

  6.   

    if Dir(PathName)="" then
      msgbox "不存在"
    else
      msgbox "存在"
    end if
      

  7.   

    dir(PathName)不行!
    PathName是进行模糊匹配
    换言之你找C:\test.txt
    如果没有C:\test.txt有个C:\te.txt它也认为找到啦!我在我遍的一个软件中是用:
    On Error Resume Next
    Dim X As Integer
    X = FreeFile
    Open SetFilePath For Input As X
    If Err.Number = 0 Then
        MsgBox "存在"
    Else
        msgbox "不存在"
    End If
      

  8.   

    to broown:你再试试,好像没有你说的模糊匹配。dir没问题。
      

  9.   

    要是用API
     Public Declare Function CreateFile Lib "kernel32" Alias "CreateFileA" (ByVal lpFileName As String, ByVal dwDesiredAccess As Long, ByVal dwShareMode As Long, lpSecurityAttributes As SECURITY_ATTRIBUTES, ByVal dwCreationDisposition As Long, ByVal dwFlagsAndAttributes As Long, ByVal hTemplateFile As Long) As Long也可以不过简单普遍的可以楼上的
      

  10.   

    呵呵,方法很多,我再加一个:
    open一下你所指定的文件名,如果出现错误了说明不存在,如果成功说明存在。当然在做这个动作之前要on error goto 一下
      

  11.   

    Option Explicit
    Dim fs As New FileSystemObjectPrivate Sub Command1_Click()
    If fs.FileExists("c:\new.mdb") Then
    MsgBox "存在"
    Else
    MsgBox "不存在"
    End If
    End Sub
      

  12.   

    如果想用FileSystemObject对象的话,
    一定要在工程里引用,Microsoft Scripting Runtime
      

  13.   

    to chinaren502(星星知我心)
     我最开始就是用dir的,但,我发现当我改名时(如:test.txt -->  tesst.txt)重新执行程序,程序提示能找到,但我一旦真正要操作这个文件时,程序就出现了错误(显然是,并没有找到这个文件)
      

  14.   

    不可能
    要操作这个文件时用dir
      

  15.   

    我也有点糊涂了!
    我用
    If Dir("c:\test.txt") = "" Then
      MsgBox "不存在"
    Else
      MsgBox "存在"
    End If
    是可以的呀。。
    如果把test.txt-->tesst.txt时就找不到了呀!!!!