Ramstack.FileProviders.Extensions
2.1.0-preview.2
See the version list below for details.
dotnet add package Ramstack.FileProviders.Extensions --version 2.1.0-preview.2
NuGet\Install-Package Ramstack.FileProviders.Extensions -Version 2.1.0-preview.2
<PackageReference Include="Ramstack.FileProviders.Extensions" Version="2.1.0-preview.2" />
paket add Ramstack.FileProviders.Extensions --version 2.1.0-preview.2
#r "nuget: Ramstack.FileProviders.Extensions, 2.1.0-preview.2"
// Install Ramstack.FileProviders.Extensions as a Cake Addin #addin nuget:?package=Ramstack.FileProviders.Extensions&version=2.1.0-preview.2&prerelease // Install Ramstack.FileProviders.Extensions as a Cake Tool #tool nuget:?package=Ramstack.FileProviders.Extensions&version=2.1.0-preview.2&prerelease
Ramstack.FileProviders.Extensions
Represents a lightweight .NET library of useful and convenient extensions for Microsoft.Extensions.FileProviders
that enhances file handling capabilities in .NET applications.
Getting Started
To install the Ramstack.FileProviders.Extensions
NuGet package
in your project, run the following command:
dotnet add package Ramstack.FileProviders.Extensions
Overview
The library provides useful extensions for IFileProvider
, bringing its capabilities and experience
closer to what's being provided by DirectoryInfo
and FileInfo
classes.
Simply stated, a FileNode
knows which directory it is located in, and a directory represented
by the DirectoryNode
class can access its parent directory and list all files within it, recursively.
FileNode file = provider.GetFile("/docs/README");
// Prints the full path of the given file
Console.WriteLine($"Reading: {file.FullName}");
using StreamReader reader = file.OpenText();
Console.WriteLine(reader.ReadToEnd());
DirectoryNode directory = provider.GetDirectory("/docs");
foreach (FileNode file in directory.EnumerateFiles())
Console.WriteLine(file.FullName);
Furthermore, the methods for enumerating files (EnumerateFiles
/EnumerateDirectories
/EnumerateFileNodes
)
allow specifying glob patterns to search for the desired files, as well as patterns to exclude files from the resulting list.
It relies on the Ramstack.Globbing package for its globbing capabilities.
DirectoryNode directory = provider.GetDirectory("/project");
// Finds all *.md files and converts them to HTML
foreach (FileNode file in directory.EnumerateFiles(pattern: "**/*.md"))
RenderMarkdown(file);
// Excludes files in a specific folder
foreach (FileNode file in directory.EnumerateFiles(pattern: "**/*.md", exclude: "vendors/**"))
RenderMarkdown(file);
For convenience, many methods specific to DirectoryNode
or FileNode
are also available for IFileProvider
.
Thus, if we know the directory in which to look for files or the file to read, there is no need to obtain the
DirectoryNode
or FileNode
object.
using StreamReader reader = provider.OpenText("/docs/README", Encoding.UTF8);
Console.WriteLine(reader.ReadToEnd());
// Finds all *.md files and converts them to HTML
foreach (FileNode file in provider.EnumerateFiles("/project", pattern: "**/*.md"))
RenderMarkdown(file);
Related Packages
- Additional file providers: Ramstack.FileProviders
- Globbing file provider: Ramstack.FileProviders.Globbing
Supported versions
Version | |
---|---|
.NET | 6, 7, 8 |
Contributions
Bug reports and contributions are welcome.
License
This package is released as open source under the MIT License. See the LICENSE file for more details.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
-
net6.0
- Microsoft.Extensions.FileProviders.Abstractions (>= 6.0.0)
- Ramstack.Globbing (>= 2.2.0-preview.3)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
2.2.1 | 126 | 9/14/2024 |
2.2.0 | 93 | 9/14/2024 |
2.1.0 | 112 | 8/28/2024 |
2.1.0-preview.3 | 54 | 8/27/2024 |
2.1.0-preview.2 | 54 | 8/26/2024 |
2.1.0-preview.1 | 83 | 8/21/2024 |
2.0.0 | 118 | 8/11/2024 |