This is an ActiveX Control that I compiled using some code that I found on an
MSDN CD-ROM. The control allows you to search for files in a whole drive
or starting at a subdirectory. You can download the latest version here
or view the readme file here.
This control has no properties or events, it just has one method - SearchFile.
Create a Form that looks like this:
Create three Label controls, two TextBoxes, a button and a ListBox and arrange
them as shown above.
If Text1.Text =
"" Then Exit Sub
the textbox is empty, then nothing can be searched for
any previous searches
Me.Enabled = False
FS1.SearchFile List1, Text2.Text, Text1.Text, Me
Me.Enabled = True
Me.Caption = "Form1" 'Clear the status bar after
When the user clicks on the search button after a file pattern has been
entered, the control will start searching for files. The Form's (Me) caption
property will be set to the directory that is currently being searched - e.g.
"Searching C:\WINDOWS". When the search is done, the results
will be shown in the ListBox. Anything that has a Caption property can be
used here e.g. Label1.
The syntax for the SearchFile method is Object.SearchFile <Listbox>,
<Search path>, <File pattern>, <Label>
The ListBox can be also be a ComboBox or any control that supports the .AddItem
method. The search path can be a whole drive - "C:\", or a
folder - "D:\Ents". The file pattern can be all files -
"*.*", files with a particular extension - "*.doc", a
specific file - "letter.doc" or any other string supported by the
FileListBox e.g. "*.wav;*.mid".
Because of the way in which the control was written, you cannot interrupt the
search i.e. closing the program in the middle of a search. Therefore, you
should disable the form and then enable it with the search code in the
middle. Interrupting the search will cause strange message boxes to appear
from the control itself.
El proyecto se podrķa mejorar muchisimo si pusiera a disposicion el
codigo fuente del OCX. Lo probe y esta muy interesante. Solo ese detalle,
incluso el boton de detener podria buscarle una solucion teniendo el
codigo fuente. Felicitaciones igualmente
what do you mean by "Have you put the control on the Form and is it
Jawahar was saying that he got the error message 'Object Required'
when attempting to compile the above code. This code needs a File
Search control to be named FS1. If Jawahar did not have a File
Search control called FS1, this may be the cause of the error he was
Friday, December 7, 2007 at 13:33:13
i want to thx u for that control
Sunday, August 19, 2007 at 10:42:41
What is 'Me' actually..
'Me' refers to the Form you are writing the code in. For the
above code, it is the equivalent of 'Form1'.
Hi... This works excellent... But In my form I want only the names of
the file... As I am using combo box to help the user choose a particular
For example: "d:\spkfiles" has all "*.spk" files and
at the back end I want to assign the file name to a variable for further
As in if for example after searching, in the combo box it has found
"d:\spkfiles\sam.spk" file. I need only "sam" listed
or even if it is not listed I should be somehow able to extract only the
name "sam" and assign it to a variable at the back end...
Can Anyone help me with my problem ??? I hope my problem is clear. i
want to use the name of the file... and not its entire path !!!!
To do this, you need to specify a hidden ListBox for the results of
the search. You then need to create a loop to add only the last
part of the filename to a visible ListBox or ComboBox. You can do
this with the following code:
For i = 0 To lstHid.ListItems - 1 'hidden ListBox
l = lstHid.List(i)
Combo1.AddItem = Right(l, Len(l) - InStrRev(l, "\"))
The ListIndex property of the selected item in the visible list is
used as the reference to get the full filename from the hidden list.
Thursday, March 29, 2007 at 12:15:36
This works ok, but search is not similar to windows search. If there are 4 files abc2 03.txt, abc2 04.txt, abc20 03.txt,abc20 04.txt, if search for files in windows with filter as abc20*.txt, it'll return last 2 files, but ur control returns all 4 files.....
This control can only search a hidden folder if one is specified as
the Search path. It cannot find folders nested in the Search path
e.g. if "C:\WINDOWS" is the Search path, the "INF"
folder would be missed even though it contains files, which are not
Sunday, August 14, 2005 at 18:14:29
What sort of "object" are you talking about?
The Object refers to the File Search object. The download link
is at the top of this page.
Thursday, May 19, 2005 at 19:55:38
Hey! this is great! found over 2000 files in under 5 seconds. excelent
What is I wanted to add a button to stop a serach in progress, does this control support that? Such as FS1.Stop
Unfortunately I did not include this when I compiled this
control. As the code is available on the MSDN CD-ROM, you could
look for it on there and use it in your program. That way, you
could change it to suit you.
Martin Allen 1999 - 2011. Last updated
Wednesday 10 August 2011 07:31:56 PM +0100.