• Lexical
Show / Hide Table of Contents
  • Lexical.FileSystem
    • Introduction
    • Abstractions
      • IFileSystem
        • IFileSystem
        • IFileSystemBrowse
        • IFileSystemCreateDirectory
        • IFileSystemDelete
        • IFileSystemFileAttribute
        • IFileSystemMount
        • IFileSystemMove
        • IFileSystemObserve
        • IFileSystemOpen
      • IEvent
      • IEntry
      • IOption
      • IToken
    • FileSystem
    • VirtualFileSystem
    • MemoryFileSystem
    • EmbeddedFileSystem
    • HttpFileSystem
    • Decoration
    • IFileProvider
    • Utility
      • DisposeList
      • FileScanner
      • VisitTree
      • File Operation
  • Lexical.FileProvider
    • Introduction
    • Package
    • Package.Abstractions
    • Root
    • Zip
    • Dll
    • SharpCompress
    • SharpZipLib
    • FileScanner
    • Utils
  • Lexical.Localization
    • Introduction
    • Tutorial
    • Asset
      • IAsset
      • IStringAsset
    • Line
      • ILine
      • ILineFactory
      • ILineRoot
      • ILineFormat
      • ILineLogger
      • LineComparer
    • File
      • ILineReader
      • ILineWriter
      • Ini
      • Json
      • Xml
      • Resx
      • Resources
    • Miscellaneous
      • Plurality
      • ICulturePolicy
      • IStringFormat
      • Dependency Injection
    • Practices
      • Class Library
      • Class Library DI
      • Class Library DI opt.
  • Lexical.Utilities
    • Introduction
    • UnicodeString
    • FileScanner
    • Permutation
    • Tuples
    • StructList

Lexical.FileProvider.Root

RootFileProvider is a file provider that enables OS wide file paths such as volumes.

RootFileProvider fileProvider = new RootFileProvider();

Constructor delegate can be given as argument. This is useful for configuring PhysicalFilePath exclusion filters.

RootFileProvider fileProvider = new RootFileProvider(
    path => new PhysicalFileProvider(path, ExclusionFilters.None)
);

.GetDirectoryContents("") returns all drive letters on windows and the root "/" on linux.

foreach (IFileInfo fileinfo in fileProvider.GetDirectoryContents(null))
    Console.WriteLine(fileinfo.Name);
C:
D:
E:
/

.GetDirectoryContents("C:/") and .GetDirectoryContents("C:\") returns the root of that drive letter.

foreach (IFileInfo fileinfo in fileProvider.GetDirectoryContents("C:/"))
    Console.WriteLine(fileinfo.Name);
foreach (IFileInfo fileinfo in fileProvider.GetDirectoryContents("C:\\"))
    Console.WriteLine(fileinfo.Name);

Relative paths, such as "." and ".." are relative to the current working directory.

foreach (IFileInfo fileinfo in fileProvider.GetDirectoryContents("."))
    Console.WriteLine(fileinfo.Name);

Windows network drives "\\server\name/path" are accessed with back-slashes.

foreach (IFileInfo fileinfo in fileProvider.GetDirectoryContents(@"\\192.168.8.200\shared"))
    Console.WriteLine(fileinfo.Name);

FileScanner can scan relative drive and file on the computer.

int count = 0;
foreach (string filepath in new FileScanner(fileProvider).AddGlobPattern("**").SetReturnDirectories(true))
{
    Console.WriteLine(filepath);
    if (++count == 100) break;
}
fileProvider.Dispose();

And network drives too. Note that file scanner uses '/' as internal separator, therefore the network path must have '/' as first folder separator.

foreach (string filepath in new FileScanner(fileProvider).AddWildcard(@"\\192.168.8.200\shared/*"))
    Console.WriteLine(filepath);

Links

  • Lexical.FileProvider.Root (Web, NuGet, Git)
Back to top Copyright © 2015-2020 Toni Kalajainen