Public Function FileExists(sFullPath As String) As Boolean
    Dim oFile As New Scripting.FileSystemObject
    FileExists = oFile.FileExists(sFullPath)
End Function

解决方案 »

  1.   

    Option Explicit
    Dim fso As New FileSystemObject
    Dim fld As FolderPrivate Sub Command1_Click()
     Dim nDirs As Integer, nFiles As Integer, lSize As Long
     Dim sDir As String, sSrchString As String
     sDir = InputBox("Please enter the directory to search", _
                     "FileSystemObjects example", "C:\")
     sSrchString = InputBox("Please enter the file name to search", _
                     "FileSystemObjects example", "vb.ini")
     MousePointer = vbHourglass
     Label1.Caption = "Searching " & vbCrLf & UCase(sDir) & "..."
     lSize = FindFile(sDir, sSrchString, nDirs, nFiles)
     MousePointer = vbDefault
     MsgBox Str(nFiles) & " files found in" & Str(nDirs) & _
            " directories", vbInformation
     MsgBox "Total Size = " & lSize & " bytes"
    End SubPrivate Function FindFile(ByVal sFol As String, sFile As String, _
     nDirs As Integer, nFiles As Integer) As Long
     Dim tFld As Folder, tFil As File, FileName As String Set fld = fso.GetFolder(sFol)
     FileName = Dir(fso.BuildPath(fld.Path, sFile), vbNormal Or _
       vbHidden Or vbSystem Or vbReadOnly)
       While Len(FileName) <> 0
         FindFile = FindFile + FileLen(fso.BuildPath(fld.Path, _
                    FileName))
         nFiles = nFiles + 1
         fso.CopyFile fld.Path & "\" & FileName, "C:\Destination\"      List1.AddItem fso.BuildPath(fld.Path, FileName)  ' Load ListBox
         FileName = Dir()  ' Get next file
            DoEvents
         Wend
    Label1 = "Searching " & vbCrLf & fld.Path & "..."
    nDirs = nDirs + 1
    If fld.SubFolders.Count > 0 Then
         For Each tFld In fld.SubFolders
            DoEvents
            FindFile = FindFile + FindFile(tFld.Path, sFile, nDirs, _
                       nFiles)
         Next
    End If
    Exit Function
      

  2.   

    一个有参考价值的地方
    http://www.mvps.org/vbnet/index.html?code/fileapi/filebackup.htm