• Avalanche
  • Lexical SDK
  • Avalanche SDK
Show / Hide Table of Contents
  • Avalanche.Service
    • Introduction
    • Service
    • Handler
    • Request
    • Dependency Injection
    • Events
    • Examples
      • Quick Start
      • Expression
      • Mapper
  • Avalanche.Accessor
    • Introduction
    • Events
  • Avalanche.DataType
    • Introduction
    • Events
  • Avalanche.Binding
    • Introduction
    • Type
    • Events
  • Avalanche.Serialization
    • Introduction
    • Events
  • Avalanche.Localization
    • Introduction
    • Events
  • Avalanche.Converter
    • Introduction
    • Events
  • Avalanche.FileSystem
    • Introduction
    • Abstractions
      • IFileSystem
        • IFileSystemBrowse
        • IFileSystemCreateDirectory
        • IFileSystemDelete
        • IFileSystemFileAttribute
        • IFileSystemMount
        • IFileSystemMove
        • IFileSystemObserve
        • IFileSystemOpen
      • IEvent
      • IEntry
      • IOption
      • IToken
    • FileSystem
    • VirtualFileSystem
    • MemoryFileSystem
    • EmbeddedFileSystem
    • HttpFileSystem
    • Decoration
    • IFileProvider
    • Events
    • Utilities
      • Dispose
      • File Scanner
      • Visit Tree
      • File Operation
  • Avalanche.Core
    • Introduction
    • Events
  • Avalanche.Utilities
    • Introduction
    • UnicodeString
    • Permutation
    • Tuples
    • StructList

FileScanner

FileScanner scans the tree structure of a filesystem for files that match its configured criteria. It uses concurrent threads.

IFileSystem fs = new MemoryFileSystem();
fs.CreateDirectory("myfile.zip/folder");
fs.CreateFile("myfile.zip/folder/somefile.txt");

FileScanner filescanner = new FileScanner(fs);

FileScanner needs to be populated with at least one filter, such as wildcard pattern, .AddWildcard(string).

filescanner.AddWildcard("*.zip");

Or regular expression.

filescanner.AddRegex(path: "", pattern: new Regex(@".*\.zip"));

Or glob pattern.

filescanner.AddGlobPattern("**.zip/**.txt");

The initial start path is extracted from the pattern.

filescanner.AddGlobPattern("myfile.zip/**.txt");

Search is started when IEnumerator<IEntry> is enumerated from the scanner.

foreach (IEntry entry in filescanner)
{
    Console.WriteLine(entry.Path);
}

Exceptions that occur at real-time can be captured into concurrent collection.

// Collect errors
filescanner.errors = new ConcurrentBag<Exception>();
// Run scan
IEntry[] entries = filescanner.ToArray();
// View errors
foreach (Exception e in filescanner.errors) Console.WriteLine(e);

The property .ReturnDirectories determines whether scanner returns directories.

filescanner.ReturnDirectories = true;

The property .SetDirectoryEvaluator(Func<IEntry, bool> func) sets a criteria that determines whether scanner enters a directory.

filescanner.SetDirectoryEvaluator(e => e.Name != "tmp");
Back to top Copyright © 2017-2021 Toni Kalajainen, contact@avalanche.fi