What recls.NET Offers Above .NET's Search Facilities
You may be reading this and thinking "but there have been standard facilities for recursive filesystem search since CLR version 2". And you'd be right.
GetDirectories() methods have a third overload that takes a parameter of type
System.IO.SearchOption, which has the enumerators
AllDirectories. And it's the same for
So what does recls 100% .NET provide that is not available in the standard libraries?
- Multi-part patterns. Passing "*.dll|*.exe" to Directory.GetFiles() will throw an argument exception, and passing "*.dll;*.exe" will simply return no results.
- Depth-control. With the CLR facilities you have only two choices: no recursion or infinite recursion.
- IEntry - so you don't have to ask twice (DirectoryInfo.GetFiles()/GetDirectories() do return arrays of FileInfo/DirectoryInfo)
- Filtering of hidden & system files. DirectoryInfo.GetFiles() always includes hidden and system files.
- Ignoring inaccessible directories. An UnauthorizedAccessException is thrown by DirectoryInfo.GetFiles() when asking for all files for a directory that contains an inaccessible subdirectory (like the "System Volume Information" directory sitting in the root level on each local hard drive). Recls allows you to handle this, by specifying handler (via delegate or interface), or to skip any such items via specifying
- Search-relative path. When I'm writing non-trivial filesystem manipulation programs -- such as recursive comparisons, recursive copying, and so on -- I find the
SearchRelativePathinvaluable. Writing such programs without it would be burdensome, to say the least.
As mentioned earlier, recls 100% .NET does not currently provide FTP searching. That's something that might be added in a later version, though at this stage it looks doubtful. Without a commercial imperative to do so it's likely to languish at the end of one of my long to-do lists.
Also, the new version does not support the specification of multiple patterns where one or more includes a sub-directory, as in:
This will be added in a future version.
I am considering a future facility to treat the patterns parameter as a regular expression, which would probably be indicated by a new
SearchOptions flag. (The main reason I haven't yet is I'm still in two minds about whether (and how) to handle multiple patterns in that form. I'm definitely interested in opinions from users/readers on the subject.)
Finally, other languages will be getting the recls 100% treatment, probably starting with Ruby or Python next year.
Obtaining recls 100% .NET
recls 100% .NET is available, from http://recls.net. The download includes the library (which incorporates all the core functionality discussed in this article) along with documentation (Intellisense XML and CHM), and example projects.
I'd like to thank my .NET posse -- Chris Oldwood, Garth Lancaster, John O'Halloran and Joy Chan -- for their assistance in keeping me to the point and making it interesting. Any failures are my own fault for inadequately addressing their concerns.
 The recls project; http://recls.org/
 Introducing recls, Matthew Wilson, C/C++ Users Journal, November 2003
 Extended STL, volume 1: Collections and Iterators, Matthew Wilson, Addison-Wesley, 2007
 Quality Matters, Part 1: Introductions, and Nomenclature, Matthew Wilson, Overload 92, August 2009
 Code Complete, 2nd Edition, Steve McConnell, Microsoft Press, 2004
 An Enhanced ostream_iterator, Matthew Wilson, Dr. Dobb's Journal, June 2007
 C# In Depth, Jon Skeet, Manning, 2008
 More Effective C#, Bill Wagner, Addison-Wesley, 2009
Matthew Wilson is a software development consultant and trainer for Synesis Software who helps clients to build high-performance software that does not break, specializing in C++ and C#/.NET. He is the author of the books Imperfect C++ and Extended STL, a columnist for ACCU, and a resident guru at Dr. Dobb's CodeTalk, focusing on Windows technologies. He can be contacted at email@example.com.