10Tec Company
top bar image
Free Newsletter
Your e-mail:


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.

 
In this section:
Download Demo
  Back to Top
Visit our partners:
Visual Basic News & Information Source Tools and components for software developers ViewSlip - Perfest products for your business! Quality Tools for Serious Microsoft Developers Shareup Networks Downloads vbAccelerator.com Download software from TopShareware.com Shareware and Freeware downloads and tested, rated and reviewed software submitted by software author.
Everything Visual Basic, from Visual Basic 3 to Visual Basic Xml Upload.com: a web service for promoting and selling software online
© 10Tec Company. Last updated: 20 Mar 2008