Lexical.FileScanner
Lexical.FileProviders.FileScanner is a configurable scanner that searches for files and folders. It is configurable to match file paths against wildcards, regular expressions, and glob patterns. It uses all threads concurrently, which makes it effective for opening package files.
// Create root file provider
PhysicalFileProvider root = new PhysicalFileProvider(Directory.GetCurrentDirectory());
// Create package options
IPackageFileProviderOptions options =
new PackageFileProviderOptions()
.AddPackageLoaders(Dll.Singleton, Exe.Singleton, Zip.Singleton, Rar.Singleton, _7z.Singleton,
Tar.Singleton, GZip.Singleton, BZip2.Singleton, Lzw.Singleton);
// Create package file provider
using (var fileProvider = new PackageFileProvider(root, options).AddDisposable(root))
{
// Glob scan with multiple threads
string[] files = new FileScanner(fileProvider)
.AddGlobPattern("**.zip/**.resources")
.OrderBy(s => s)
.ToArray();
// Print
foreach (String filename in files)
Console.WriteLine(filename);
}
Errors that are thrown by file provider are captured. .SetErrorTarget(IProducerConsumerCollection<Exception>) sets a target where captured errors are to be placed.
int count = 0;
ConcurrentBag<Exception> errors = new ConcurrentBag<Exception>();
foreach (string filepath in new FileScanner(fileProvider).AddGlobPattern("**").SetErrorTarget(errors))
{
// Print errors
Exception e;
if (errors.TryTake(out e)) Console.Error.WriteLine(e);
Console.WriteLine(filepath);
if (++count == 100) break;
}
fileProvider.Dispose();