If Dir("c:\winnt", vbDirectory) <> "" Then
        MsgBox "存在"
    Else
        MsgBox "不存在"
    End If

解决方案 »

  1.   

    用FSO
    '引用Microsoft Scripting Runtime
    Option Explicit
    Dim fsoSys As New Scripting.FileSystemObject
    Dim fsoFile As FilePrivate Sub Command1_Click()
      Dim temp As String
      Dim CreateDate As Variant
      If Not fsoSys.FileExists("c:\netlog.txt") Then
        MsgBox "文件不存在"
      Else
        Set fsoFile = fsoSys.GetFile("c:\netlog.txt")
        temp = "文件名:" & fsoFile.Name & vbCrLf
        temp = temp & "文件类型:" & fsoFile.Type & vbCrLf
        temp = temp & "文件大小:" & CStr(fsoFile.Size) & "字节" & vbCrLf
        '因为在win98下无法测试创建时间,代码应该类似下面
        'CreateDate = fsoFile.DateCreated
        'temp = temp & "创建时间:" & CDate(CreateDate) & vbcrlf
        temp = temp & "修改时间:" & fsoFile.DateLastModified
        RichTextBox1.Text = temp
      End If
    End Sub
      

  2.   

    谢谢大家,我明白了。还有一个问题不知道大家能不能帮忙。
    如何获得一个BYTE数组的大小。也就是类似len(aaa)一样的功能。
      

  3.   

    其实上面的写法都不是特别好。第一种方法,有些时候是有错误的。用FSO的话,需要包括scrrun.dll 文件。看看Microsoft是怎么判断文件是否存在的。'-----------------------------------------------------------
    ' FUNCTION: FileExists
    ' Determines whether the specified file exists
    '
    ' IN: [strPathName] - file to check for
    '
    ' Returns: True if file exists, False otherwise
    '-----------------------------------------------------------
    '
    Function FileExists(ByVal strPathName As String) As Integer
        Dim intFileNum As Integer    On Error Resume Next    '
        ' If the string is quoted, remove the quotes.
        '
        strPathName = strUnQuoteString(strPathName)
        '
        'Remove any trailing directory separator character
        '
        If Right$(strPathName, 1) = gstrSEP_DIR Then
            strPathName = Left$(strPathName, Len(strPathName) - 1)
        End If    '
        'Attempt to open the file, return value of this function is False
        'if an error occurs on open, True otherwise
        '
        intFileNum = FreeFile
        Open strPathName For Input As intFileNum    FileExists = IIf(Err = 0, True, False)    Close intFileNum    Err = 0
    End Function