Ramstack.FileSystem.Abstractions
                              
                            
                                1.5.1
                            
                        
                    dotnet add package Ramstack.FileSystem.Abstractions --version 1.5.1
NuGet\Install-Package Ramstack.FileSystem.Abstractions -Version 1.5.1
<PackageReference Include="Ramstack.FileSystem.Abstractions" Version="1.5.1" />
<PackageVersion Include="Ramstack.FileSystem.Abstractions" Version="1.5.1" />
<PackageReference Include="Ramstack.FileSystem.Abstractions" />
paket add Ramstack.FileSystem.Abstractions --version 1.5.1
#r "nuget: Ramstack.FileSystem.Abstractions, 1.5.1"
#:package Ramstack.FileSystem.Abstractions@1.5.1
#addin nuget:?package=Ramstack.FileSystem.Abstractions&version=1.5.1
#tool nuget:?package=Ramstack.FileSystem.Abstractions&version=1.5.1
Ramstack.FileSystem.Abstractions
Provides a virtual file system abstraction.
For current implementations, see Related Projects
Getting Started
To install the Ramstack.FileSystem.Abstractions NuGet package
in your project, run the following command:
dotnet add package Ramstack.FileSystem.Abstractions
Overview
The primary interface is IVirtualFileSystem, which exposes methods to:
- Access files (VirtualFile).
- Access directories (VirtualDirectory).
VirtualFile
The VirtualFile class provides properties and methods for creating, deleting, copying and opening files within the virtual file system.
using Ramstack.FileSystem;
public class Program
{
    public static async Task Sample(IVirtualFileSystem fs)
    {
        var file = fs.GetFile("/sample/hello.txt");
        Console.WriteLine($"Writing 'Hello, World!' to '{file.FullName}'");
        await using (Stream stream = await file.OpenWriteAsync())
        await using (StreamWriter writer = new StreamWriter(stream))
        {
            await writer.WriteLineAsync("Hello, World!");
        }
        Console.WriteLine($"Reading contents of '{file.FullName}'");
        using (StreamReader reader = await file.OpenTextAsync())
        {
            Console.WriteLine(await reader.ReadToEndAsync());
        }
        // Replace content of the file with data from an existing file
        await using FileStream input = File.OpenRead(@"D:\sample\hello-world.txt");
        await file.WriteAsync(input, overwrite: true);
        Console.WriteLine($"The file '{file.Name}' has a length of {await file.GetLengthAsync()} bytes");
        Console.WriteLine($"Deleting file '{file.FullName}'");
        await file.DeleteAsync();
    }
}
The VirtualFile class provides the following properties to retrieve information about a file:
- FileSystem: Gets the- IVirtualFileSystemassociated with the file.
- Directory: Gets the- VirtualDirectoryrepresenting the parent directory.
- DirectoryName: Gets the full path of the parent directory.
- IsReadOnly: Indicates whether the file is read-only.
- Name: Gets the name of the file.
- Extension: Gets the extension of the file.
The VirtualFile class also exposes a GetPropertiesAsync method to retrieve file properties:
- Length: Gets the size of the file in bytes.
- Exists: Indicates whether the file exists.
- CreationTime: Gets the creation time of the file.
- LastAccessTime: Gets the last access time of the file.
- LastWriteTime: Gets the last modification time of the file.
For convenience, many methods specific to VirtualFile are also available as extension methods on IVirtualFileSystem.
For example, if we know the path of the file we want to read, we don't need to obtain a VirtualFile object explicitly:
using StreamReader reader = await fs.OpenTextAsync("/docs/README", Encoding.UTF8);
Console.WriteLine(await reader.ReadToEndAsync());
VirtualDirectory
The VirtualDirectory class provides properties and methods for creating, deleting and enumerating directories and subdirectories.
public static async Task PrintFilesAsync(VirtualDirectory directory, string padding = "", CancellationToken cancellationToken = default)
{
    await foreach (VirtualNode node in directory.GetFileNodesAsync(cancellationToken))
    {
        Console.WriteLine($"{padding}{node.Name}");
        if (node is VirtualDirectory dir)
        {
            await PrintFilesAsync(dir, padding + "   ", cancellationToken);
        }
    }
}
// Print the file tree
await PrintFilesAsync(fs.GetDirectory("/sample"));
The VirtualDirectory class provides the following properties to retrieve information about a directory:
- FileSystem: Gets the- IVirtualFileSystemassociated with the directory.
- IsRoot: Indicates whether the directory is the root directory.
- Parent: Gets the- VirtualDirectoryrepresenting the parent directory.
- DirectoryName: Gets the full path of the parent directory.
- IsReadOnly: Indicates whether the directory is read-only.
- Name: Gets the name of the directory.
The VirtualDirectory class also exposes a GetPropertiesAsync method to retrieve directory properties, if available:
- Exists: Indicates whether the directory exists.
- CreationTime: Gets the creation time of the directory.
- LastAccessTime: Gets the last access time of the directory.
- LastWriteTime: Gets the last modification time of the directory.
- Length: Always returns- 0for directories.
For convenience, many methods specific to VirtualDirectory are also available as extension methods on IVirtualFileSystem.
For example, if we know the path of the desired directory, we don't need to obtain a VirtualDirectory object explicitly:
await foreach (VirtualFile file in fs.GetFilesAsync("/sample/directory"))
{
    Console.WriteLine($"Processing: {file.FullName}");
}
// Delete the directory recursively
await fs.DeleteDirectoryAsync("/sample/directory");
Remark
The file system in use may be read-only, and as a result, any modifying operations on files and directories will throw an exception.
To check if the file system is read-only, the IVirtualFileSystem, VirtualFile and VirtualDirectory classes provide the IsReadOnly property.
if (!fs.IsReadOnly)
{
    await fs.DeleteFileAsync("/hello.txt");
}
Related Projects
- Ramstack.FileSystem.Physical - Provides an implementation based on the local file system.
- Ramstack.FileSystem.Azure - Provides an implementation using Azure Blob storage.
- Ramstack.FileSystem.Amazon - Provides an implementation using Amazon S3 storage.
- Ramstack.FileSystem.Google - Provides an implementation using Google Cloud storage.
- Ramstack.FileSystem.Readonly - Provides a read-only wrapper for the underlying file system.
- Ramstack.FileSystem.Globbing - Wraps the file system, filtering files and directories using glob patterns.
- Ramstack.FileSystem.Prefixed - Adds a prefix to file paths within the underlying file system.
- Ramstack.FileSystem.Sub - Wraps the underlying file system, restricting access to a specific subpath.
- Ramstack.FileSystem.Adapters - Provides integration with Microsoft.Extensions.FileProviders.
- Ramstack.FileSystem.Composite - Provides an implementation that combines multiple file systems into a single composite file system.
Supported Versions
| Version | |
|---|---|
| .NET | 6, 7, 8, 9, 10 | 
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. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. | 
- 
                                                    net6.0- Ramstack.Globbing (>= 2.3.2)
 
NuGet packages (12)
Showing the top 5 NuGet packages that depend on Ramstack.FileSystem.Abstractions:
| Package | Downloads | 
|---|---|
| Ramstack.FileSystem.Zip Provides an implementation of Ramstack.FileSystem for managing files within ZIP archives. | |
| Ramstack.FileSystem.Readonly Provides an implementation of Ramstack.FileSystem that wraps the underlying file system, preventing any destructive operations. | |
| Ramstack.FileSystem.Azure Provides an implementation of Ramstack.FileSystem based on Azure Blob Storage. | |
| Ramstack.FileSystem.Prefixed Provides an implementation of Ramstack.FileSystem that adds a specified prefix to the file paths within the underlying file system. | |
| Ramstack.FileSystem.Adapters Provides adapters for integrating Ramstack.FileSystem with Microsoft.Extensions.FileProviders. | 
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated | 
|---|---|---|
| 1.5.1 | 591 | 9/17/2025 | 
| 1.5.0 | 426 | 8/31/2025 | 
| 1.4.1 | 453 | 8/17/2025 | 
| 1.4.0 | 484 | 8/10/2025 | 
| 1.3.0 | 488 | 8/4/2025 | 
| 1.2.3 | 337 | 7/31/2025 | 
| 1.2.2 | 447 | 7/15/2025 | 
| 1.2.1 | 407 | 7/9/2025 | 
| 1.2.0 | 439 | 4/23/2025 | 
| 1.1.1 | 492 | 9/14/2024 | 
| 1.1.0 | 452 | 9/14/2024 | 
| 1.0.1 | 456 | 9/13/2024 | 
| 1.0.0 | 412 | 9/13/2024 | 
| 1.0.0-preview.9 | 105 | 9/10/2024 | 
| 1.0.0-preview.8 | 115 | 9/5/2024 | 
| 1.0.0-preview.7 | 90 | 9/4/2024 | 
| 1.0.0-preview.6 | 88 | 9/3/2024 | 
| 1.0.0-preview.5 | 107 | 8/30/2024 | 
| 1.0.0-preview.4 | 130 | 8/24/2024 | 
| 1.0.0-preview.3 | 128 | 8/22/2024 | 
| 1.0.0-preview.2 | 112 | 8/21/2024 | 
| 1.0.0-preview.1 | 94 | 8/20/2024 |