ScopeFolder Object
ScopeFolders
Corresponds to a searchable folder. ScopeFolder objects are intended for use with the SearchFolders collection. The SearchFolders collection defines the folders that are searched when using the FileSearch object. When you want to search specific folders you can use the methods and properties of the SearchScope object and ScopeFolders collection to retrieve ScopeFolder objects and add them to the SearchFolders collection.
Using the ScopeFolder object
Use the ScopeFolder property of the SearchScope object to return the root ScopeFolder object of a search scope; for example:
Set sf = Application.FileSearch.SearchScopes.Item(1).ScopeFolder
Use the Item method of the ScopeFolders collection to return a subfolder of a root ScopeFolder object; for example:
Set sf = Application.FileSearch.SearchScopes.Item(1).ScopeFolder.ScopeFolders.Item(1)
Use the Item method of the SearchFolders collection to return a folder that will be searched the next time the Execute method of the FileSearch object is called; for example:
Set sf = Application.FileSearch.SearchFolders.Item(1)
In each ScopeFolder object there is a ScopeFolders collection that contains the subfolders of the parent ScopeFolder object. You can traverse the entire folder structure of a search scope (for example, all local drives) by looping through these ScopeFolders collections and returning all of the lower-level ScopeFolder objects. A ScopeFolder object with no subfolders contains an empty ScopeFolders collection.
For an example that demonstrates how to loop through all of the ScopeFolder objects in a search scope, see the SearchFolders collection topic.
You can use the Add method of the SearchFolders collection to add a ScopeFolder object to the SearchFolders collection, however, it is usually simpler to use the AddToSearchFolders method of the ScopeFolder that you want to add, as there is only one SearchFolders collection for all searches.
For an example that demonstrates how to add a ScopeFolder to the SearchFolders collection, see the SearchFolders collection topic.
The following example displays the root path of each directory in My Computer. To retrieve this information, the example first gets the ScopeFolder object at the root of My Computer. The path of this ScopeFolder object will always be "*". As with all ScopeFolder objects, the root object contains a ScopeFolders collection. This example loops through this ScopeFolders collection and displays the path of each ScopeFolder object in it. The paths of these ScopeFolder objects will be "A:\", "C:\", etc.
Sub DisplayRootScopeFolders()
'Declare variables that reference a
'SearchScope and a ScopeFolder object.
Dim ss As SearchScope
Dim sf As ScopeFolder
'Use a With...End With block to reference the
'FileSearch object.
With Application.FileSearch
'Loop through the SearchScopes collection
'and display all of the root ScopeFolders collections in
'the My Computer scope.
For Each ss In .SearchScopes
Select Case ss.Type
Case msoSearchInMyComputer
'Loop through each ScopeFolder object in
'the ScopeFolders collection of the
'SearchScope object and display the path.
For Each sf In ss.ScopeFolder.ScopeFolders
MsgBox "ScopeFolder object's path: " & sf.Path
Next sf
Case Else
End Select
Next
End With
End Sub