- 浏览: 769314 次
- 性别:
- 来自: 大连
文章分类
- 全部博客 (417)
- ASP.NET MVC (18)
- WEB基础 (24)
- 数据库 (69)
- iPhone (20)
- JQuery (3)
- Android (21)
- UML (8)
- C# (32)
- 移动技术 (19)
- 条码/RFID (6)
- MAC (8)
- VSS/SVN (6)
- 开卷有益 (4)
- 应用软件 (1)
- 软件工程 (1)
- java/Eclipse/tomcat (61)
- 英语学习 (2)
- 综合 (16)
- SharePoint (7)
- linux (42)
- Solaris/Unix (38)
- weblogic (12)
- c/c++ (42)
- 云 (1)
- sqlite (1)
- FTp (2)
- 项目管理 (2)
- webservice (1)
- apache (4)
- javascript (3)
- Spring/Struts/Mybatis/Hibernate (4)
- 航空业务 (1)
- 测试 (6)
- BPM (1)
最新评论
-
dashengkeji:
1a64f39292ebf4b4bed41d9d6b21ee7 ...
使用POI生成Excel文件,可以自动调整excel列宽等(转) -
zi_wu_xian:
PageOffice操作excel也可以设置表格的行高列宽,并 ...
使用POI生成Excel文件,可以自动调整excel列宽等(转) -
wanggang0321:
亲,我在pptx(office2007以上版本)转pdf的时候 ...
JODConverter]word转pdf心得分享(转) -
xiejanee:
楼主:你好!我想请问下 你在代码中用DOMDocument* ...
Xerces-C++学习之——查询修改XML文档 (转)
- 转自: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.
/// < 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)) { disksListBox.Items.Add( Ch+ @" :" ); } } } }
Application shows alerts when you check a not-ready disk.
In the WinSearchFile application, I use threads to make the same search simultaneously on different targets; I use a thread for each target drive.
/// < SUMMARY > /// Start search /// < / SUMMARY > /// < PARAM name="sender" > < / PARAM > /// < PARAM name="e" > < / PARAM > private void btnSearch_Click(object sender, System.EventArgs e) { // empty thread list for (int i = thrdList.ItemCount()-1; i>=0; i--) { thrdList.RemoveItem(i); } // clear the file founded list listFileFounded.Items.Clear(); ContainingFolder = " " ; // get the search pattern // or use a default SearchPattern = txtSearchPattern.Text.Trim(); if (SearchPattern.Length == 0 ) { SearchPattern = " *.*" ; } // get the text to search for SearchForText = txtSearchText.Text.Trim(); // clear the Dirs arraylist Dirs.Clear(); // check if each selected drive exists foreach (int Index in disksListBox.CheckedIndices) { // chek if drive is ready String Dir = disksListBox.Items[Index].ToString().Substring(0 ,2 ); Dir += @" \" ; if (CheckExists(Dir)) { Dirs.Add(Dir); } } // I use 1 thread for each dir to scan foreach (String Dir in Dirs) { Thread oT; string thrdName = " Thread" + ((int )(thrdList.ItemCount()+1)).ToString(); FileSearch fs = new FileSearch(Dir, SearchPattern, SearchForText, CaseSensitive, this , thrdName); oT = new Thread(new ThreadStart(fs.SearchDir)); oT.Name = thrdName; SearchThread st = new SearchThread(); st.searchdir = Dir; st.name = oT.Name; st.thrd = oT; st.state = SearchThreadState.ready; thrdList.AddItem(st); oT.Start(); } }
Data about searching threads is stored in a list, and during the search process, you can see how many threads are running/ready/cancelled.
Threads use the FileSearch
class to do their work. To
update controls or data structures on main threads, use delegate
functions. I defined a delegate function for the AddListBoxItem
method:
/// < SUMMARY > /// Delegate for AddListBoxItem /// < / SUMMARY > public delegate void AddListBoxItemDelegate(String Text); /// < SUMMARY > /// Add a new item to the file founded list /// < / SUMMARY > /// < PARAM name="Text" > < / PARAM > public void AddListBoxItem(String Text) { // I use Monitor to synchronize access // to the file founded list Monitor.Enter(listFileFounded); listFileFounded.Items.Add(Text); Monitor.Exit(listFileFounded); }
and one to update the thread state:
/// < SUMMARY > /// Delegate for UpdateThreadStatus function /// < / SUMMARY > public delegate void UpdateThreadStatusDelegate(String thrdName, SearchThreadState sts); /// < SUMMARY > /// Store the new state of a thread /// < / SUMMARY > /// < PARAM name="thrdName" > < / PARAM > /// < PARAM name="sts" > < / PARAM > public void UpdateThreadStatus(String thrdName, SearchThreadState sts) { SearchThread st = thrdList.Item(thrdName); st.state = sts; }
On clicking the "Stop search" button, all the running threads are cancelled using the Abort
method.
/// < SUMMARY > /// Stop searching /// < / SUMMARY > /// < PARAM name="sender" > < / PARAM > /// < PARAM name="e" > < / PARAM > private void btnStop_Click(object sender, System.EventArgs e) { // some threads are running if (InProgress) { // Abort each searching thread in running status // and change its status to cancelled for (int i= 0 ; i < thrdList.ItemCount(); i++) { if (((SearchThread)thrdList.Item(i)).state == SearchThreadState.running) { ((SearchThread)thrdList.Item(i)).state = SearchThreadState.cancelled; Thread tt; try { tt = ((SearchThread)thrdList.Item(i)).thrd; tt.Abort(); } catch { } } } } }
On double clicking on a result listbox item, WinSearchFile will open the corresponding containing folder.
To quick launch WinSearchFile, you can create a shortcut to it on your desktop and assign to this one a shortcut key.
Conclusion
I hope you enjoy this article.
New WinSearchFile version
The new WinSearchFile 2.0, built using Visual Studio 2005 and C# 2.0, contains the following new features:
- Single Instance Application using code written by Eric Bergman-Terrell .
- Search inside PDF files.
- Regular expression searching.
- Searching using IFilter.
- Max directory visit depth.
- File
Creation Time
orLast ACcess Time
orLast Write Time
searching - directory list to search into.
-
Save results
button.
Here is a new screenshot:
About IFilter
User can decide to use installed IFilter to extract plaintext from files. To implement this interface I used 2 class developed by Dan Letecky .
The following code shows where I try to use IFilter to get plaintext:
public static bool FileContainsText(String FileName, String SearchForText, bool CaseSensitive, bool UseRegularExpression, bool UseIFilter) { bool Result = (SearchForText.Length == 0 ); if (!Result) { // try to use IFilter if you have checked // UseIFilter checkbox if (Parser.IsParseable(FileName) && UseIFilter) { string content = Parser.Parse(FileName); // if content length > 0 // means that IFilter works and returns the file content // otherwise IFilter hadn't read the file content // i.e. IFilter seems no to be able to extract // text contained in dll or exe file if (content.Length > 0 ) { Result = containsPattern(SearchForText, CaseSensitive, UseRegularExpression, content); return Result; } } // scan files to get plaintext // with my routines if (FileName.ToLower().EndsWith(" .pdf" )) { // search text in a pdf file Result = SearchInPdf(FileName, SearchForText, CaseSensitive, UseRegularExpression); } else { bool Error; String TextContent = GetFileContent(FileName, out Error); if (!Error) { Result = containsPattern(SearchForText, CaseSensitive, UseRegularExpression, TextContent); } } } return Result; }
The following screenshot shows the about box where it's possible to get the list of installed IFilter. To get this list I used a class developed by vbAccelerator.com .
License
This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)
About the Author
Massimo Beatini
Member |
|
发表评论
-
项目中业务的一致性,完整性
2013-11-28 15:17 0a.一致性:A系统和主机都保留一份座位图数据,就容易导致两 ... -
excel根据列值调整行颜色
2013-04-23 16:43 1591http://www.360doc.com/content/1 ... -
jenkins
2013-04-15 10:54 798http://www.chineselinuxunivers ... -
日常note
2013-04-10 14:09 01.有时需要打开cmd窗口,来运行诸如bat程序,但是有时候 ... -
invoke
2013-03-15 15:53 0object Object.Invoke(Delegate ... -
JQuery的WebServices调用
2013-03-14 14:12 0http://blog.sina.com.cn/s/blog_ ... -
c# list和string
2012-10-26 15:16 944C# List和String互相转换 (2011-06- ... -
.net mysql-connector-net
2012-10-19 11:10 978引用DLL引用 mysql-connector-net包中的M ... -
c# 操作mysql
2012-10-19 10:21 900using System;using System.Confi ... -
c# DataTable.copy .clone
2012-10-17 18:17 4091C# DataTable.Copy()和.Clone()的使用 ... -
C#中避免相同MDI子窗口重复打开的方法(转)
2012-10-17 13:40 1106方法一: 直接检测 ... -
C# 中使用JSON - DataContractJsonSerializer
2012-10-11 14:47 666http://www.cnblogs.com/coderzh/ ... -
论坛id
2012-07-09 11:29 0bbs.chinaunix.net ---unixfanss ... -
Intel-VT 技术详解
2012-07-06 14:41 1576Intel-VT 技术详解 ... -
号码段
2012-06-29 11:24 907中国3G号码段:中国联通185,186;中国移动188,187 ... -
【转】使用xmanager4.0 远程桌面管理redhat 5.5
2012-05-11 15:47 1889Xmanager是一个远程连接工具,里面最常用的有Xbrows ... -
.NET WHERE子句用途
2012-05-04 14:52 1491where 子句用于指定类型约束,这些约束可以作为泛型声明 ... -
c#泛型
2012-05-04 14:51 1023http://hjf1223.cnblogs.com/arch ... -
Windows Server 2008 R2:创建和加入域
2012-04-23 09:27 2406转自:http://www.ithov.com/s ... -
输出到控制台
2012-03-26 17:20 857c#:Console.Out.WriteLine(" ...
相关推荐
Quick Search 是来自glarysoft公司的一款完全免费且小巧易于使用的极速windows文件搜索工具(知名的系统优化软件中的大师Glary Utilities Pro也是glarysoft公司的力作),界面极其简洁,因为该电脑文件快速查找工具...
Ava Find、SearchMyFiles和Windows Search也提供了与 Everything 应用程序类似的功能。 什么是一切应用程序? Everything 是一个易于使用的搜索应用程序,可以帮助您查找存储在 Windows 计算机上的任何文件或...
java---文件搜索,类似于windows的文件搜索。
Quick Search 是一个带分类功能的本地硬盘文件搜索工具,如果您感觉windows的内置搜索不够用,那么这个时候Quick Search无疑是很不错的选择,可以帮您管理电脑文件,通过输入的关键字即刻找到文件与文件夹,快速查找...
如果不满意Windows自带的搜索工具、Total Commander的搜索、Google 桌面搜索或百度硬盘搜索,如果正在使用或放弃了Locate32,都值得推荐这款体积小巧、免安装、免费、速度极快(比Locate32更快)的文件搜索工具...
支持Windows和linux下搜索,命令行工具。支持模糊搜索,支持搜索类资源,比如properties文件 用法: 解压后,进入目录,修改searchClass.bat /sh 的JAVA_HOME变量 命令行: ./searchClass.sh 类全名 lib路径 or ...
文件搜索 find / -name file1 从 '/' 开始进入根文件系统搜索文件和目录 find / -user user1 搜索属于用户 'user1' 的文件和目录 find /home/user1 -name \*.bin 在目录 '/ home/user1' 中搜索带有'.bin' 结尾的...
2个目标文件,FTP的目标是:(1)提高文件的共享性(计算机程序和/或数据),(2)鼓励间接地(通过程序)使用远程计算机,(3)保护用户因主机之间的文件存储系统导致的变化,(4)为了可靠和高效地传输,虽然用户...
CreateScalableFontResource 为一种TureType字体创建一个资源文件,以便能用API函数AddFontResource将其加入Windows系统 DrawText 将文本描绘到指定的矩形中 DrawTextEx 与DrawText相似,只是加入了更多的功能 ...
复制相应 *.CTL 文件到软件安装目录,重新启动 EditPlus ,则系统自动识别。 作者主页有很多语法自动完成文件下载,地址 http://editplus.com/files.html 【14】工具集成——编译器集成例子(Java、Borland C++、...
2个目标文件,FTP的目标是:(1)提高文件的共享性(计算机程序和/或数据),(2)鼓励间接地(通过程序)使用远程计算机,(3)保护用户因主机之间的文件存储系统导致的变化,(4)为了可靠和高效地传输,虽然用户...
在 windows98 中我们常见的 chm 文件多数具有目录及索引,有的还有搜索和书签,这在使用 chm 文件的过程中会比较方便。下面我们就来制作带目录、索引、搜索、书签的 chm 文件。在这里我还将介绍一些常用的选项功能...
2个目标文件,FTP的目标是:(1)提高文件的共享性(计算机程序和/或数据),(2)鼓励间接地(通过程序)使用远程计算机,(3)保护用户因主机之间的文件存储系统导致的变化,(4)为了可靠和高效地传输,虽然用户...
1.跨平台系统,能无差别的运行于Windows、Linux、Mac OS等操作系统。 2.★拥有云端版本更新通知服务器,可在后台获取官方的最新版本及每次更新的版本更新信息,及时通知用户进行升级。 3.★验证码支持短信、邮箱...
2个目标文件,FTP的目标是:(1)提高文件的共享性(计算机程序和/或数据),(2)鼓励间接地(通过程序)使用远程计算机,(3)保护用户因主机之间的文件存储系统导致的变化,(4)为了可靠和高效地传输,虽然用户...
2个目标文件,FTP的目标是:(1)提高文件的共享性(计算机程序和/或数据),(2)鼓励间接地(通过程序)使用远程计算机,(3)保护用户因主机之间的文件存储系统导致的变化,(4)为了可靠和高效地传输,虽然用户...
Java吃豆子游戏源代码 6个目标文件 内容索引:JAVA源码,游戏娱乐,JAVA游戏源码 JAVA编写的吃豆子游戏,类似疯狂坦克一样,至少界面有点像。大家可以看截图。 Java从网络取得文件 1个目标文件 简单 Java从压缩包中...
Java吃豆子游戏源代码 6个目标文件 内容索引:JAVA源码,游戏娱乐,JAVA游戏源码 JAVA编写的吃豆子游戏,类似疯狂坦克一样,至少界面有点像。大家可以看截图。 Java从网络取得文件 1个目标文件 简单 Java从压缩包中...
2个目标文件,FTP的目标是:(1)提高文件的共享性(计算机程序和/或数据),(2)鼓励间接地(通过程序)使用远程计算机,(3)保护用户因主机之间的文件存储系统导致的变化,(4)为了可靠和高效地传输,虽然用户...