xDir Library - Customizing
xDir events and properties can be used to implement your own search criteria. Let's suppose you want to find all files which contain the string "photo" in their names or contents, at that xDir must search the word in file contents only if the file name does not contain this word. The code that allows you to gain the goal may looks like the following (we consider that the ListBox named lstResults is populated by the sought filenames when the user presses the cmdSearch command button):
Implements IXDItemCheck
Implements IXDFoundItem
Private Sub cmdSearch_Click()
Dim xd As New xDir
xd.RootFolder = ".\TestFolder\"
xd.FileCriteria.Context.SearchPhrases = "photo"
xd.ProcessFolder Me
End Sub
Private Sub IXDFoundItem_Proc(ParentFullPath As String, _
ItemName As String, ByVal ItemType As EItemTypes, _
CancelEnum As Boolean, ByVal UserValue As Long)
lstResults.AddItem ParentFullPath & ItemName
End Sub
Private Sub IXDItemCheck_Proc(ParentFullPath As String, _
ItemName As String, ByVal ItemType As EItemTypes, _
SkipItem As Boolean, CancelEnum As Boolean, _
ByVal UserValue As Long)
If LCase$(ItemName) Like "*photo*" Then
lstResults.AddItem ParentFullPath & ItemName
SkipItem = True
End If
End Sub
The key point of this code is that you must check filenames by yourself, and force xDir to check file contents only. Simply check filename in the IXDItemCheck_Proc sub and ignore further contents search using the SkipItem parameter passed by ref. Notice that you could specify the required file mask with the following statement:
xd.FileCriteria.Mask = "*photo*"
But in this case xDir will not search "photo" inside a file because xDir checks the file mask first and searches the specified word in the file contents only if the filename matches the specified criteria.
As you can see, we have already implemented in xDir a lot of useful events and properties which allow you to implement your own file/folder search operations.
|