ByteDev.Io 7.4.1

dotnet add package ByteDev.Io --version 7.4.1                
NuGet\Install-Package ByteDev.Io -Version 7.4.1                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="ByteDev.Io" Version="7.4.1" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add ByteDev.Io --version 7.4.1                
#r "nuget: ByteDev.Io, 7.4.1"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install ByteDev.Io as a Cake Addin
#addin nuget:?package=ByteDev.Io&version=7.4.1

// Install ByteDev.Io as a Cake Tool
#tool nuget:?package=ByteDev.Io&version=7.4.1                

ByteDev.Io

Set of IO related .NET utility classes.

Installation

ByteDev.Io has been written as a .NET Standard 2.0 library, so you can consume it from a .NET Core or .NET Framework 4.6.1 (or greater) application.

ByteDev.Io is hosted as a package on nuget.org. To install from the Package Manager Console in Visual Studio run:

Install-Package ByteDev.Io

Further details can be found on the nuget page.

Release Notes

Releases follow semantic versioning.

Full details of the release notes can be viewed on GitHub.

Usage

To use these main public classes simply reference ByteDev.Io.

FileSytem

Provides a small set of methods for working with files and directories.

FileSytem methods:

  • GetPathExists
  • IsFile
  • IsDirectory
  • FirstExists
  • Exists
  • MoveFile
  • CopyFile
  • SwapFileNames
// Initialize object
IFileSystem fs = new FileSystem();
// Determine first part of path that exists

var path = fs.GetPathExists(@"C:\Temp\ThisDoesntExist\test.txt");

// path == "C:\Temp"
// Is it a file? Is it a directory?

bool isFile = fs.IsFile(@"C:\Temp\Something");
bool isDir = fs.IsDirectory(@"C:\Temp\Something");
// Return first thing that exists

string[] paths =
{
    @"C:\Temp\Test1.txt",
    @"C:\Temp\Test2.txt",
    @"C:\Temp\TestDirectory",
};

var path = fs.FirstExists(paths);
// Return info on which paths exist and which don't

string[] paths =
{
    @"C:\Temp\Test1.txt",
    @"C:\Temp\Test2.txt",
    @"C:\Temp\TestDirectory",
};

var info = fs.Exists(paths);
// Move a file

string sourceFile = @"C:\Temp\TestFile1.txt";
string destinationFile = @"C:\Windows\TestFile1.txt";

FileInfo info = fs.MoveFile(sourceFile, destinationFile, 
    FileOperationBehaviourType.DestExistsOverwrite);

// info.FullName = @"C:\Windows\TestFile1.txt" if successful
// Copy a file

string sourceFile = @"C:\Temp\TestFile1.txt";
string destinationFile = @"C:\Windows\TestFile1.txt";

FileInfo info = fs.CopyFile(sourceFile, destinationFile, 
    FileOperationBehaviourType.DestExistsOverwrite);

// info.FullName = @"C:\Windows\TestFile1.txt" if successful
// Swap two existing file's names

string file1 = @"C:\Temp\archive1.png";
string file2 = @"C:\Temp\cover.png";

fs.SwapFileNames(file1, file2);

FileSize

Represents a file size as an object.

long numberOfBytes = 1048576;

FileSize fileSize = new FileSize(numberOfBytes, FileSize.MultiplierType.DecimalMultiplier);

Console.Write(fileSize.ReadableSize);           // "1 MB"
Console.Write(fileSize.TotalBytes);             // 1048576
Console.Write(fileSize.TotalKiloBytes);         // 1048
Console.Write(fileSize.TotalMegaBytes);         // 1

FileComparer

Provides functionality to compare two files.

FileComparer methods:

  • IsSourceBigger
  • IsSourceBiggerOrEqual
  • IsSourceModifiedMoreRecently

IsolatedStorageIo

Provides functionality for isolated storage operations. To use reference namespace: ByteDev.Io.IsolatedStorage.

IsolatedStorageIo methods:

  • Exists
  • Delete
  • Write
  • Read
  • ReadAsXmlDoc
  • ReadAsXDoc
var io = new IsolatedStorageIo(IsolatedStorageFileType.UserStoreForApplication);

var fileName = new IsolatedStorageFileName("MyIsolatedFile", new Version(1, 0), ".txt");

io.Write(fileName, "Some data");

bool exists = io.Exists(fileName);

string data = io.Read(fileName);

io.Delete(fileName);

StreamFactory

Provides simple functionality to create memory streams from different input.

For example:

MemoryStream stream = StreamFactory.Create("some text");

FileLocker

Simple way to manage the locking of files.

using ByteDev.Io.Locking;

// ...

string file = @"C:\myfile.txt";

// Lock a file (myfile.txt.lock is created)
FileLockInfo fileLockInfo = FileLocker.Lock(file);

// fileLockInfo.File == new FileInfo(@"C:\myfile.txt")
// fileLockInfo.LockFile == new FileInfo(@"C:\myfile.txt.lock")

// Determine if a file is created
bool isLocked = FileLocker.IsLocked(file);

// isLocked == true

// Unlock a file (myfile.txt.lock is deleted)
FileLocker.Unlock(file);

Extension Methods

  • DirectoryInfo
    • CreateDirectory
    • DeleteIfExists
    • DeleteIfEmpty
    • DeleteDirectories
    • DeleteDirectoriesWithName
    • DeleteEmptyDirectories
    • DeleteFiles
    • DeleteFilesExcept
    • Empty
    • EmptyIfExists
    • GetAudioFiles
    • GetFilesByExtensions
    • GetImageFiles
    • GetLastModifiedFile
    • GetSize
    • GetVideoFiles
    • IsEmpty
  • FileInfo
    • AddExtension
    • DeleteIfExists
    • DeleteLine
    • DeleteLines
    • GetExtension
    • GetNextAvailableFileName
    • HasExtension
    • IsBinary
    • RenameExtension
    • RemoveExtension
    • ReplaceLine
    • ReplaceLines
  • Stream
    • IsEmpty
    • ReadAsBase64
    • ReadAsBytes
    • ReadAsMemoryStream
    • ReadAsString
    • WriteToFile
    • WriteToFileAsync
  • StreamReader
    • ReadLineKeepNewLineChars
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  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. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (2)

Showing the top 2 NuGet packages that depend on ByteDev.Io:

Package Downloads
ByteDev.Testing

.NET Standard library that provides some testing related functionality.

ByteDev.DotNet.Cleaner

Provides functionality to quickly clean .NET solutions, git repositories, user info, etc.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
7.4.1 252 9/8/2023
7.4.0 1,466 1/5/2022
7.3.0 436 10/11/2021
7.2.1 1,134 5/24/2021
7.2.0 389 3/16/2021
7.1.0 468 11/19/2020
7.0.0 455 9/30/2020
6.0.0 899 9/24/2020
5.0.0 615 4/12/2020
4.0.0 609 11/29/2019
3.2.1 792 1/19/2019
3.2.0 780 1/19/2019
3.1.0 870 10/1/2018
3.0.0 804 9/19/2018
2.0.0 1,014 5/22/2018