如何才能实现查找某个指定的文件夹下是否有某个文件,也就是说我知道某个文件的路径,例如:c:\aa\bb.exe,我想确定该目录下是否有该文件,不知道如何实现?还望指教,谢谢!

解决方案 »

  1.   

    if dir("c:\aa\bb.exe")<>"" then   msgbox "存在"
    endif
      

  2.   

    if dir("c:\aa\bb.exe")>"" then msgbox "存在"
      

  3.   

    Dim fs As Scripting.FileSystemObject    '引用中的Scriptc的三个选项都选上,才可以使
    Dim FileName As String
    Set fs = CreateObject("Scripting.FileSystemObject")
      If fs.FileExists(("c:\aa\bb.exe") = True Then
          '文件存在的操作了    
      End If
      

  4.   

    Attribute VB_Name = "ModuleExistFile"
    Option ExplicitConst OFS_MAXPATHNAME = 128
    Const OF_EXIST = &H4000Private Type OFSTRUCT
            cBytes As Byte
            fFixedDisk As Byte
            nErrCode As Integer
            Reserved1 As Integer
            Reserved2 As Integer
            szPathName(OFS_MAXPATHNAME) As Byte
    End TypePrivate typOfStruct As OFSTRUCT
    Declare Function apiOpenFile Lib "kernel32" Alias "OpenFile" (ByVal lpFileName As String, lpReOpenBuff As OFSTRUCT, ByVal wStyle As Long) As LongPublic Function Exists(ByVal sFilename As String) As Boolean
        On Error Resume Next
        If Len(sFilename) > 0 Then
            apiOpenFile sFilename, typOfStruct, OF_EXIST
            Exists = typOfStruct.nErrCode <> 2
        End If
    End FunctionExists比dir可靠
      

  5.   

    题外话一个:Exists比dir可靠,它是可靠在哪里?还望指教,谢谢!