Skip to content

mayermart/System.IO.Abstractions.Extensions

 
 

Repository files navigation

System.IO.Abstractions.Extensions NuGet Continuous Integration Renovate enabled

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.New(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.New(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.New(current.FileSystem.Path.Combine(current.FullName, "test.txt")).Create())
    stream.Dispose();

IDirectoryInfo.CopyTo extension

var fs = new FileSystem();
var current = fs.CurrentDirectory();

//source
var source =  fs.DirectoryInfo.New(fs.Path.Combine(current.FullName, "SourceDir"));

//destination
var dest =  fs.DirectoryInfo.New(fs.Path.Combine(current.FullName, "DestDir"));

//copy
source.CopyTo(dest, recursive: true);

About

Convenience functionality on top of System.IO.Abstractions

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C# 100.0%