Soenneker.Utils.Path
11.0.1275
Prefix Reserved
dotnet add package Soenneker.Utils.Path --version 11.0.1275
NuGet\Install-Package Soenneker.Utils.Path -Version 11.0.1275
<PackageReference Include="Soenneker.Utils.Path" Version="11.0.1275" />
<PackageVersion Include="Soenneker.Utils.Path" Version="11.0.1275" />
<PackageReference Include="Soenneker.Utils.Path" />
paket add Soenneker.Utils.Path --version 11.0.1275
#r "nuget: Soenneker.Utils.Path, 11.0.1275"
#:package Soenneker.Utils.Path@11.0.1275
#addin nuget:?package=Soenneker.Utils.Path&version=11.0.1275
#tool nuget:?package=Soenneker.Utils.Path&version=11.0.1275
Soenneker.Utils.Path
Reserves collision-free file names, creates unique temporary directories, and generates GUID-based path candidates.
Installation
dotnet add package Soenneker.Utils.Path
Quick start
using Soenneker.Utils.Path.Registrars;
services.AddPathUtilAsSingleton();
Then inject IPathUtil wherever you need it.
GetTempDirectory and GetLastPathSegment are static helpers on PathUtil. The unique-path and
temp-directory operations are exposed through IPathUtil.
Reserve a file name from a URI
string path = await pathUtil.GetUniqueFilePathFromUri(
downloadDirectory,
"https://example.com/files/report.pdf",
cancellationToken);
This method extracts the URI path's file name and atomically creates an empty file to reserve it.
If report.pdf already exists, it tries report(1).pdf, report(2).pdf, and so on. The directory
must already exist. The caller owns the reserved file and should overwrite it or delete it when no
longer needed. Non-collision filesystem failures propagate rather than being retried forever.
Generate random candidate paths
string candidate = await pathUtil.GetRandomUniqueFilePath(outputDirectory, ".json", cancellationToken);
string tempCandidate = await pathUtil.GetRandomTempFilePath("tmp", cancellationToken);
These methods return GUID-based paths that did not exist when checked; they do not create or
reserve files. Another process can claim a result before it is opened. Use FileMode.CreateNew
when the caller needs atomic ownership and retry on a collision. Extensions with or without a
leading dot are accepted; path components are discarded.
Create a temporary directory
string workspace = await pathUtil.GetUniqueTempDirectory("import", create: true, cancellationToken);
try
{
// Use workspace.
}
finally
{
Directory.Delete(workspace, recursive: true);
}
The default create: true atomically creates a GUID-suffixed directory below the process temp
directory. With create: false, the method only returns a currently unused candidate and has the
same check-then-use race as random file paths. Prefix path components are removed. Cleanup remains
the caller's responsibility.
PathUtil.GetTempDirectory() returns the process-cached value of Path.GetTempPath().
PathUtil.GetLastPathSegment(path) ignores trailing platform directory separators and returns
null for empty or separator-only input; it does not access the filesystem.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net11.0 is compatible. |
-
net11.0
- Soenneker.Extensions.String (>= 11.0.820)
- Soenneker.Utils.ExecutionContexts (>= 11.0.53)
NuGet packages (4)
Showing the top 4 NuGet packages that depend on Soenneker.Utils.Path:
| Package | Downloads |
|---|---|
|
Soenneker.Utils.Directory
A utility library encapsulating various directory methods |
|
|
Soenneker.Blob.Download
A utility library for Azure Blob download operations |
|
|
Soenneker.Utils.File.Download
Provides a flexible utility for downloading files from specified URIs, with thread-safe concurrency and automatic file name conflict handling |
|
|
Soenneker.Pdfs.Processor
A PDF-library-free .NET utility for replacing text, merging, cleaning, and optimizing PDF documents. |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 11.0.1275 | 4,539 | 11/11/2026 |
| 11.0.1274 | 2,915 | 11/11/2026 |
| 11.0.1273 | 1,663 | 11/11/2026 |
| 11.0.1272 | 1,691 | 11/11/2026 |
| 11.0.1271 | 381 | 11/11/2026 |
| 11.0.1270 | 2,419 | 11/11/2026 |
| 11.0.1269 | 16,379 | 11/3/2026 |
| 11.0.1268 | 2,268 | 11/3/2026 |
| 11.0.1267 | 3,733 | 11/2/2026 |
| 11.0.1266 | 20,913 | 10/26/2026 |
| 11.0.1265 | 168 | 10/26/2026 |
| 4.0.1264 | 22,926 | 10/15/2026 |
| 4.0.1263 | 98 | 10/15/2026 |
| 4.0.1262 | 132 | 10/14/2026 |
| 4.0.1261 | 1,023 | 10/14/2026 |
| 4.0.1259 | 2,938 | 10/14/2026 |
| 4.0.1258 | 3,368 | 10/14/2026 |
| 4.0.1251 | 2,291 | 10/13/2026 |
| 4.0.1250 | 1,211 | 10/13/2026 |
| 4.0.1247 | 7,409 | 10/12/2026 |
Updated Soenneker.Extensions.String to 11.0.820