kreeben
12-30-2004, 03:38 AM
Does anybody know of a file search algorithm that I can use to search a hard drive for files of a specific type, say .txt files. I need it to get a list of file paths. I am considering writing my own algorithm to scan large directory structures but I am quite concerned about the speed and the processing power needed for such an operation. A typical Windows installation consists of hundreds of directories and thousands of files. Will the System.IO classes perform well in such a large operation?
kreeben
12-30-2004, 05:48 AM
I found a basic files/directories listing algorithm here (thx excaliber):
http://www.xtremevbtalk.com/showthread.php?t=158264
By using that code and supplying a search string to DirectoryInfo.GetFiles I can now search directories for specific file types. It is not that fast but it works. By scanning "c:\windows\system32" for "*.dll" files I found 1718 files and 191 folders in 13 seconds. This was done on Windows XP SP2, Celeron 2.5 GHz and 256 MB RAM. Please note that instead of writing to the debug, as excalibers code does, I am writing to a multiline textbox.
Anybody got faster code?
kreeben
12-30-2004, 08:24 AM
Another question, if I was to store the resulting file paths (using excalibers code, see first post), what kind of collection should I use so that adding items to the collection would have the smallest possible impact on performance? Should I use a VB Array? Doesn´t redimming an array take an awful lot of time? Should I use a string collection? After all, the file paths are strings (I´m not using the Path class). Should I use an ArrayList?
kreeben
01-03-2005, 08:33 AM
Well, as always, I am talking to myself ;-)
Too whomever it may concern - the system.io.directoryinfo class seems to be just about as fast as you can get. The time consuming part of a file search action seems to be writing to a log file. A search through the windows\system32 directory looking for dll files found around 2000 files in under a second. Pretty good, I would say.
Oh, and I used an arraylist to store the resulting System.IO.FileInfo objects.