The Artima Developer Community
Sponsored Link

C++ Community News Forum
Synesis Software Releases The New recls 100% .NET Library

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Matthew Wilson

Posts: 145
Nickname: bigboy
Registered: Jun, 2004

Synesis Software Releases The New recls 100% .NET Library Posted: Nov 12, 2009 3:33 PM
Reply to this message Reply
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.

foreach(IEntry entry in FileSearcher.BreadthFirst.Search(null, null, SearchOptions.Directories | SearchOptions.IgnoreInaccessibleNodes, 0))
{
    Console.WriteLine("{0} : {1}", entry.Path, FileSearcher.CalculateDirectorySize(entry, FileSearcher.UnrestrictedDepth));
}

Example 4

Get an entry representing a given path.

IEntry entry = FileSearcher.Stat(@"H:\freelibs\recls\100\recls.net\recls.100.sln");

if(null == entry)
{
    Console.Error.Write("file not found");
}
else
{
    Console.WriteLine("{0,20}:\t{1}", "Path", entry.Path);
    Console.WriteLine("{0,20}:\t{1}", "SearchRelativePath", entry.SearchRelativePath);
    Console.WriteLine("{0,20}:\t{1}", "Drive", entry.Drive);
    Console.WriteLine("{0,20}:\t{1}", "DirectoryPath", entry.DirectoryPath);
    Console.WriteLine("{0,20}:\t{1}", "Directory", entry.Directory);
    Console.WriteLine("{0,20}:\t{1}", "SearchDirectory", entry.SearchDirectory);
    Console.WriteLine("{0,20}:\t{1}", "UncDrive", entry.UncDrive);
    Console.WriteLine("{0,20}:\t{1}", "File", entry.File);
    Console.WriteLine("{0,20}:\t{1}", "FileName", entry.FileName);
    Console.WriteLine("{0,20}:\t{1}", "FileExtension", entry.FileExtension);
    Console.WriteLine("{0,20}:\t{1}", "CreationTime", entry.CreationTime);
    Console.WriteLine("{0,20}:\t{1}", "ModificationTime", entry.ModificationTime);
    Console.WriteLine("{0,20}:\t{1}", "LastAccessTime", entry.LastAccessTime);
    Console.WriteLine("{0,20}:\t{1}", "LastStatusChangeTime", entry.LastStatusChangeTime);
    Console.WriteLine("{0,20}:\t{1}", "Size", entry.Size);
    Console.WriteLine("{0,20}:\t{1}", "Attributes", entry.Attributes);
    Console.WriteLine("{0,20}:\t{1}", "IsReadOnly", entry.IsReadOnly);
    Console.WriteLine("{0,20}:\t{1}", "IsDirectory", entry.IsDirectory);
    Console.WriteLine("{0,20}:\t{1}", "IsUnc", entry.IsUnc);
    Console.WriteLine("{0,20}:\t[{1}]", "DirectoryParts", String.Join(", ", entry.DirectoryParts));
}

Gives the following results:

                                Path:   H:\freelibs\recls\100\recls.net\recls.100.sln
                  SearchRelativePath:   recls.100.sln
                               Drive:   H:
                       DirectoryPath:   H:\freelibs\recls\100\recls.net\
                           Directory:   \freelibs\recls\100\recls.net\
                     SearchDirectory:   H:\freelibs\recls\100\recls.net\
                            UncDrive:
                                File:   recls.100.sln
                            FileName:   recls.100
                       FileExtension:   .sln
                        CreationTime:   31/07/2009 11:40:44 AM
                    ModificationTime:   20/08/2009 3:40:00 PM
                      LastAccessTime:   20/08/2009 3:46:33 PM
                LastStatusChangeTime:   20/08/2009 3:40:00 PM
                                Size:   34157
                          Attributes:   ReadOnly, Archive, Compressed
                          IsReadOnly:   True
                         IsDirectory:   False
                               IsUnc:   False
                      DirectoryParts:   [\, freelibs\, recls\, 100\, recls.net\]

Topic: Effective C++ in an Embedded Environment Previous Topic   Next Topic Topic: FastFormat 0.3.5 released

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use