搜索中的目录和子目录的文件的最快的方法 [英] Fastest Way of Searching a file within Directories and SubDirectories
问题描述
我要搜索的目录和子目录中的文件的最快方式。文件的数量超过140万。文件大小范围5至50 KB。每个文件夹包含5到10000个文件。
目前我使用的时刻:
的foreach(在Directory.GetFiles字符串文件(路径,*。*,SearchOption.AllDirectories))
{
如果(file.Contains(searchkeyword))
{
字符串AnchorText = Path.GetFileNameWithoutExtension(文件);
}
}
最佳的解决方案
我会索引添加到该目录并使用<一个href=\"http://stackoverflow.com/questions/4131420/querying-windows-file-indexing-service-using-c-sharp\">Windows搜索查找文件,在它的。这里的优势不仅在于它是不是你需要维护,但也是Windows索引服务能够索引文件(.DOC,.PDF,.TXT等)的内容。 土生土长的解决方案 一个数据库里有一个土生土长缓存(* SQL中,Redis的,蒙戈,Lucene的,不管你preFER)。 当你需要搜索的文件只是查询数据库。 I need the fastest way to search for files within directories and subdirectories. The number of files is more than 1.4 Million. File sizes range between 5 and 50 KB. Each folder contains 5 to 10000 files. At the moment I am using:
Best Solution I would add an index to that directory and use Windows Search to find files in it. The advantages here are not only that it isn't code that you need to maintain but also that the Windows Indexing Service is able to index the contents of files (.doc, .pdf, .txt, etc.). Home-Grown Solution A home-grown cache inside of a database (*Sql, Redis, Mongo, Lucene, whatever you prefer). When you need to search for a file simply query the database. 这篇关于搜索中的目录和子目录的文件的最快的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋! FileSystemWatcher的
的目录,当你启动应用程序。foreach (string file in Directory.GetFiles(path, "*.*", SearchOption.AllDirectories))
{
if (file.Contains(searchkeyword))
{
string AnchorText = Path.GetFileNameWithoutExtension(file);
}
}
FileSystemWatcher
to the directory when your application starts.