TestableIO.System.IO.Abstractions.Extensions 22.0.4
Convenience functionality on top of System.IO.Abstractions
dotnet add package TestableIO.System.IO.Abstractions.Extensions
Examples
CurrentDirectory extension
var fs = new FileSystem();
//with extension
var current = fs.CurrentDirectory();
//without extension
var current = fs.DirectoryInfo.FromDirectoryName(fs.Directory.GetCurrentDirectory());
SubDirectory extension
var current = new FileSystem().CurrentDirectory();
//create a "temp" subdirectory with extension
current.SubDirectory("temp").Create();
//create a "temp" subdirectory without extension
current.FileSystem.DirectoryInfo.FromDirectoryName(current.FileSystem.Path.Combine(current.FullName, "temp")).Create();
File extension
var current = new FileSystem().CurrentDirectory();
//create a "test.txt" file with extension
using (var stream = current.File("test.txt").Create())
stream.Dispose();
//create a "test.txt" file without extension
using (var stream = current.FileSystem.FileInfo.FromFileName(current.FileSystem.Path.Combine(current.FullName, "test.txt")).Create())
stream.Dispose();
Automatic cleanup with Disposable extensions
Use CreateDisposableDirectory or CreateDisposableFile to create a IDirectoryInfo or IFileInfo that's automatically
deleted when the returned IDisposable is disposed.
var fs = new FileSystem();
//with extension
using (fs.CreateDisposableDirectory(out IDirectoryInfo dir))
{
Console.WriteLine($"This directory will be deleted when control leaves the using block: '{dir.FullName}'");
}
//without extension
var temp = fs.Path.GetTempPath();
var fileName = fs.Path.GetRandomFileName();
var path = fs.Path.Combine(temp, fileName);
try
{
IDirectoryInfo dir = fs.Directory.CreateDirectory(path);
Console.WriteLine($"This directory will be deleted in the finally block: '{dir.FullName}'");
}
finally
{
fs.Directory.Delete(path, recursive: true);
}
IDirectoryInfo.CopyTo extension
var fs = new FileSystem();
var current = fs.CurrentDirectory();
//source
var source = current.SubDirectory("source");
source.Create(); //make sure the source directory exists
//destination
var dest = current.SubDirectory("destination");
//copy
source.CopyTo(dest, recursive: true);
No packages depend on TestableIO.System.IO.Abstractions.Extensions.
# Release Notes
List of notable changes between majors
## 22.0.0
- (Breaking) Removed support for some Async calls in .NET Framework and
legacy versions of .NET to better support .NET 8 and later
- Minimum required TestableIO.System.IO.Abstractions version is now 22.x
- Removed .NET 7 build (should still work with .NET standard build)
- Removed .NET 6 build (should still work with .NET standard build)
## 2.0.0
- (Breaking) Moved all extensions methods to 'System.IO.Abstractions' namespace
- Added ThrowIfNotFound extension methods
- Removed .NET 5 build (should still work with .NET standard build)
.NET Framework 4.7.2
- TestableIO.System.IO.Abstractions (>= 22.0.14)
.NET 8.0
- TestableIO.System.IO.Abstractions (>= 22.0.14)
.NET Standard 2.0
- TestableIO.System.IO.Abstractions (>= 22.0.14)
.NET Standard 2.1
- TestableIO.System.IO.Abstractions (>= 22.0.14)
| Version | Downloads | Last updated |
|---|---|---|
| 22.0.4 | 2 | 08/25/2025 |
| 22.0.3 | 2 | 08/25/2025 |
| 22.0.2 | 2 | 08/25/2025 |
| 22.0.1 | 2 | 08/25/2025 |
| 2.2.6 | 2 | 08/24/2025 |
| 2.2.5 | 3 | 06/16/2025 |
| 2.2.4 | 2 | 08/24/2025 |
| 2.2.3 | 2 | 08/24/2025 |
| 2.2.1 | 2 | 08/24/2025 |
| 2.1.3 | 2 | 08/24/2025 |
| 2.1.2 | 2 | 08/24/2025 |
| 2.1.1 | 2 | 08/24/2025 |
| 2.0.5 | 2 | 08/24/2025 |
| 2.0.4 | 2 | 08/24/2025 |
| 2.0.3 | 2 | 08/24/2025 |
| 2.0.2 | 2 | 08/24/2025 |
| 2.0.1 | 2 | 08/24/2025 |
| 1.0.43 | 2 | 08/25/2025 |
| 1.0.42 | 2 | 08/25/2025 |
| 1.0.41 | 2 | 08/25/2025 |
| 1.0.40 | 2 | 08/25/2025 |
| 1.0.39 | 2 | 08/25/2025 |
| 1.0.38 | 2 | 08/25/2025 |
| 1.0.37 | 2 | 08/25/2025 |
| 1.0.36 | 2 | 08/25/2025 |
| 1.0.35 | 2 | 08/25/2025 |
| 1.0.34 | 2 | 08/25/2025 |
| 1.0.32 | 2 | 08/25/2025 |
| 1.0.30 | 2 | 08/25/2025 |
| 1.0.28 | 2 | 08/25/2025 |
| 1.0.24 | 2 | 08/25/2025 |
| 1.0.23 | 2 | 08/25/2025 |
| 1.0.22 | 2 | 08/25/2025 |
| 1.0.21 | 2 | 08/25/2025 |
| 1.0.20 | 2 | 08/25/2025 |
| 1.0.19 | 2 | 08/25/2025 |
| 1.0.17 | 2 | 08/25/2025 |
| 1.0.16 | 2 | 08/25/2025 |
| 1.0.14 | 2 | 08/25/2025 |