Summary
recls 100% .NET is a .NET 2/3 library that provides recursive file-system search. The library supports breadth-first or depth-first search of files and/or directories, hidden and/or system files, specification of multi-part wildcard patterns, marking of directories, error and progress delegates, and other advanced features.
Advertisement
The next phase in the life of the popular recls recursive file-system search library is recls 100%: a series of 100%-pure per-language implementations. The first of these, recls 100% .NET, is a 100%-C# implementation, which has the following features:
breadth-first / depth-first search
search of files and/or directories
searching of hidden and/or system files/directories
specification of multi-part patterns, e.g. "*.cpp|makefile"
marking of directories with a trailing slash
error callback interface / delegate
progress callback interface / delegate
skipping of inaccessible directories
rich representation of file/directory entries, including path, directory, name, size, timestamps, directory parts, and more
recls 100% .NET is a donationware product, and is available from http://recls.net. It is written to production-quality standards, yet is available for free, and may be used without restriction in commercial and/or non-commercial software systems. Users are asked to make a donation to the recls project to help ensure that the project is actively maintained and improved.
recls 100% .NET is very easy to use, based around the FileSearcher static class, which defines methods, constants and delegates for file-system enumeration. File-system entries are represented by the IEntry interface, which defines a number of properties representing the entry's characteristics. The following examples illustrate some of the available functionality:
Example 1
List all font files in the windows directory or any of its subdirectories.
foreach(IEntry entry in FileSearcher.Search(@"C:\windows", "*.fon|*.ttf"))
{
Console.WriteLine(entry.Path);
}
Example 2
Search for all program and DLL files (including hidden) smaller than 10k in the current directory and all sub-directories up to 3 deep, reporting on any entries that cannot be enumerated. This example uses an anonymous delegate for the error handling, and LINQ for filtering and selecting the entry members.
var files = FileSearcher.DepthFirst.Search( // search in depth-first manner
null, // search current directory
"m*.exe|n*.dll", // all programs beginning with m; all DLLs beginning with n
SearchOptions.IncludeHidden, // include hidden files/directories
3, // descend at most 3 directories
null, // don't need progress callback
delegate(string path, Exception x)
{
// report on any entries that could not be enumerated, but ...
Console.Error.WriteLine("could not enumerate {0}: {1}", path, x.Message);
// ... continue the enumeration
return ExceptionHandlerResult.ConsumeExceptionAndContinue;
}
);
var results = from file in files
where file.Size < 10240
select file.SearchRelativePath;
foreach(var path in results)
{
Console.WriteLine("entry: {0}", path);
}
Example 3
Display the names and sizes of all the immediate sub-directories of the current directory. The example uses the Recls extension method ForEach() in combination with a lambda expression.
FileSearcher.BreadthFirst.Search(
null, // search current directory
null, // all names
SearchOptions.Directories | SearchOptions.IgnoreInaccessibleNodes, // only want dirs; don't worry about inaccessible entries
0 // do not recurse
)
.ForEach((d) => Console.WriteLine("{0} : {1}", d.Path, FileSearcher.CalculateDirectorySize(d.Path, FileSearcher.UnrestrictedDepth)));
This can also be expressed in a more conventional syntax.