日期:2014-05-17  浏览次数:20774 次

类似Windows Search的文件搜索系统
  • 转自:http://www.cnblogs.com/wuhenke/archive/2010/04/08/1707691.html
  • Download source files [.NET 1.1] - 35.9 Kb
  • Download source files [.NET 2.0] - 860 Kb

?

?

Introduction

WinSearchFile is a program that I developed and I usually use it to search files on my PC.

Sometimes the search engine integrated with Explorer doesn't work fine, especially when I try to find text contained into files, so I decided to build my own search program.

There are a lot of search programs available to install on your PC but this one, without indexing your data, is simple and fast enough to help you in your search.

Inside the application

WinSearchFile layout is simple and quite similar to the Explorer integrated search. It is possible to write a pattern search (wildcards admitted) and/or a text to search into file contents (you can also decide for a case sensitive search).

In the "look in" area, you have all the disks of your computer (network connection included). To obtain this list, I use the DiskCollection class developed by dmihailescu in his Get Logical Drives Information article.

Collapse Copy Code
///
 <
SUMMARY
>


///
 Add items for all floppy, 

///
 CD and hard drives.

///
 <
/
SUMMARY
>


private
 void
 LoadDisksComboBox()
{
    disksListBox.Items.Clear();

    //
 Try to use DiskCollection

    //
 retrieving drive information

    DiskCollection diskColl = new
 DiskCollection();
    if
 ( diskColl.Load() )
    {
        foreach
(DiskCollection.LogicalDriveInfo diskinfo in
 diskColl)
        {
            disksListBox.Items.Add(diskinfo.Name.ToString() + 
                                "
: "
+ diskinfo.Description );

        }
    }
    else

    {
        //
 otherwise build a drive list checking 

        //
 if a root directory exists

        for
 (char
 Ch = '
A'
; Ch <= '
Z'
; Ch++)
        {
            string
 Dir = Ch + @"
:\"
;

            if
 (Directory.Exists(Dir))