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);