Soenneker.Utils.File 11.0.2329

Prefix Reserved
There is a newer version of this package available.
See the version list below for details.
dotnet add package Soenneker.Utils.File --version 11.0.2329
                    
NuGet\Install-Package Soenneker.Utils.File -Version 11.0.2329
                    
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="Soenneker.Utils.File" Version="11.0.2329" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Soenneker.Utils.File" Version="11.0.2329" />
                    
Directory.Packages.props
<PackageReference Include="Soenneker.Utils.File" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Soenneker.Utils.File --version 11.0.2329
                    
#r "nuget: Soenneker.Utils.File, 11.0.2329"
                    
#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.
#:package Soenneker.Utils.File@11.0.2329
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Soenneker.Utils.File&version=11.0.2329
                    
Install as a Cake Addin
#tool nuget:?package=Soenneker.Utils.File&version=11.0.2329
                    
Install as a Cake Tool

alternate text is missing from this package README image alternate text is missing from this package README image alternate text is missing from this package README image alternate text is missing from this package README image

Soenneker.Utils.File

DI-friendly asynchronous file reading, writing, copying, moving, enumeration, metadata, and cleanup operations.

Installation

dotnet add package Soenneker.Utils.File

Registration

builder.Services.AddFileUtilAsSingleton();

AddFileUtilAsScoped() is also available and registers the memory-stream dependency with the matching lifetime.

Read and write

string text = await files.Read(path, cancellationToken: cancellationToken);
List<string> lines = await files.ReadAsLines(path, cancellationToken: cancellationToken);
byte[] bytes = await files.ReadToBytes(path, cancellationToken: cancellationToken);

await files.Write(path, text, cancellationToken: cancellationToken);
await files.Append(path, "next entry\n", cancellationToken: cancellationToken);

Text writes use UTF-8 without a byte-order mark. Reads detect a byte-order mark when present. Whole-file methods materialize the complete contents; use OpenRead() for large or streaming workloads.

TryRead() and TryReadToHashSet() return null and optionally log when reading fails. Requested cancellation still throws OperationCanceledException rather than being converted to null.

Stream ownership

await using FileStream input = files.OpenRead(path);
await using FileStream output = files.OpenWrite(destinationPath);

using MemoryStream buffered = await files.ReadToMemoryStream(path, cancellationToken: cancellationToken);

The caller owns every stream returned by this package. OpenWrite() creates missing parent directories and truncates an existing file. Write(path, sourceStream) copies from the source's current position, leaves the source open, and replaces the destination contents.

Copy and move

await files.Copy(sourcePath, destinationPath, cancellationToken: cancellationToken);
await files.Move(sourcePath, archivePath, cancellationToken: cancellationToken);
await files.CopyRecursively(sourceDirectory, destinationDirectory, cancellationToken: cancellationToken);

Copy() creates the destination parent and overwrites the destination. It is not transactional: a failed or cancelled copy can leave a partial destination.

Move() uses the filesystem's native overwrite move when available. Its cross-volume fallback copies to a temporary file beside the destination, publishes that completed copy, then deletes the source. If cancellation occurs after publication but before source deletion, both complete files can remain.

Recursive copy skips inaccessible entries and does not follow symbolic links, junctions, or other reparse points. It copies discovered files and their required parent directories; empty source directories are not reproduced.

Deletion and bulk mutation

bool removed = await files.DeleteIfExists(path, cancellationToken: cancellationToken);
await files.DeleteAll(directory, cancellationToken: cancellationToken);

DeleteAll() removes only files immediately inside the directory, not descendants. TryDelete(), TryDeleteIfExists(), and TryDeleteAll() convert I/O failures to false, but propagate requested cancellation.

Bulk rename, attribute removal, recursive copy, and multi-file deletion are incremental operations. Cancellation or a later conflict does not undo earlier filesystem changes. Resolve and validate any user-controlled root path before calling destructive methods.

Product Compatible and additional computed target framework versions.
.NET net11.0 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (41)

Showing the top 5 NuGet packages that depend on Soenneker.Utils.File:

Package Downloads
Soenneker.Utils.Json

Serializes, deserializes, validates, formats, and writes JSON with System.Text.Json.

Soenneker.Git.Util

Asynchronous Git operations, repository discovery, and bounded batch processing using bundled Git distributions.

Soenneker.Utils.Dotnet

A utility library for the dotnet executable

Soenneker.Blob.Download

A utility library for Azure Blob download operations

Soenneker.Google.Credentials

Loads service-account JSON files from LocalResources and caches Google credentials by ordered OAuth scopes.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
11.0.2333 0 11/3/2026
11.0.2332 0 11/3/2026
11.0.2331 0 11/3/2026
11.0.2330 0 11/3/2026
11.0.2329 14,985 10/28/2026
11.0.2328 17,079 10/26/2026
11.0.2326 2,702 10/26/2026
11.0.2325 4,442 10/26/2026
11.0.2324 1,621 10/26/2026
11.0.2322 491 10/26/2026
11.0.2321 1,060 10/26/2026
4.0.2320 3,900 10/26/2026
4.0.2319 38,196 10/15/2026
4.0.2318 1,282 10/14/2026
4.0.2316 4,853 10/14/2026
4.0.2315 6,125 10/14/2026
4.0.2314 6,739 10/14/2026
4.0.2311 972 10/14/2026
4.0.2303 6,926 10/13/2026
4.0.2301 1,348 10/13/2026
Loading failed

Update dependency Soenneker.Utils.MemoryStream to 11.0.1607 (#3236)