FoundFiles Object

Description

Represents the list of files returned from a file search.

Using the FoundFiles Object

Use the FoundFiles property to return the FoundFiles object. This example steps through the list of found files and displays the path and file name of each found file.

With Application.FileSearch
    For i = 1 To .FoundFiles.Count
        MsgBox .FoundFiles(i)
    Next I
End With
Use FoundFiles(index), where index is the index number, to return the path and file name of a found file. The following example steps through the collection of found files and displays the path and file name of each one.

With Application.FileSearch
For i = 1 To .FoundFiles.Count
    MsgBox .FoundFiles(i)
Next I
End With
Use the Execute method to begin the file search and update the FoundFiles object. The following example searches the My Documents folder for all files whose names begin with "Cmd" and displays the name and location of each file that's found. The example also sorts the returned files in ascending alphabetic order by file name.

Set fs = Application.FileSearch
With fs
    .LookIn = "C:\My Documents"
    .FileName = "cmd*"
    If .Execute(SortBy:=msoSortbyFileName, _
        SortOrder:=msoSortOrderAscending) > 0 Then
        MsgBox "There were " & .FoundFiles.Count & _
            " file(s) found."
        For i = 1 To .FoundFiles.Count
            MsgBox .FoundFiles(i)
        Next i
    Else
        MsgBox "There were no files found."
    End If
End With