VillageSoftware.PathMatcher 1.0.2.1

dotnet add package VillageSoftware.PathMatcher --version 1.0.2.1
NuGet\Install-Package VillageSoftware.PathMatcher -Version 1.0.2.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="VillageSoftware.PathMatcher" Version="1.0.2.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add VillageSoftware.PathMatcher --version 1.0.2.1
#r "nuget: VillageSoftware.PathMatcher, 1.0.2.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 VillageSoftware.PathMatcher as a Cake Addin
#addin nuget:?package=VillageSoftware.PathMatcher&version=1.0.2.1

// Install VillageSoftware.PathMatcher as a Cake Tool
#tool nuget:?package=VillageSoftware.PathMatcher&version=1.0.2.1

VillageSoftware.PathMatcher

This is a .Net Standard 1.3 library to do some things that System.IO.Path doesn't do. Its design goals include being thoroughly tested and easily integrated. We aim to make this a trustworthy library for working with mixed URL and Local-style file paths and in particular, resituating files from a local context into the cloud.

In principle, importing this module should keep you from doing work that's already been done by us in a proven, well-tested way.

Setup

In NuGet Package Manager:

Install-Package VillageSoftware.PathMatcher

Or see VillageSoftware.PathMatcher on nuget.org

Features

PathInfo class

The PathInfo class is instantiated on a path string and exposes a load of helpful properties and methods. It is needed as the basis of the more complex tools in the library.

Properties:

  • pathInfo.FilePath - The path
  • pathInfo.FileDirectoryOnly - The directory (without the file)
  • pathInfo.FileNameOnly - The file name (without the directory)
  • pathInfo.Chunks - FilePath as a List of chunks (segments)
  • pathInfo.Separator - The (calculated) predominant separator in the path
  • pathInfo.IsUrl - True if FilePath is considered to be a URL
  • pathInfo.HasTerminatingSeparator - True if FilePath currently has a terminating separator

Methods:

  • GetPathWithFinalSeparatorOnOff(string path, bool showFinalSeparator) - Ensure that the passed path either has or does not have a trailing separator (using the predominant Separator)
  • PathBeforeChunk(string chunk) and PathAfterChunk - Return the reamining section of FilePath which appears before/after the specified chunk (segment)
  • ConformSeparatorTo(char separator) - Change the separators on this PathInfo object to the specified separator and rebuild all of the PathInfo fields (this is useful for merging together local \ paths and remote / paths)
  • AddChunks(bool addTerminatingSeparator, params string[] chunks) - Lengthen the path safely, automatically inserting the predominant separator between your new specified chunks. Optionally add a terminating separator.
  • SetFileName(string FileName) - Set the file name of this PathInfo to the filename found in the supplied parameter (or pass "" to remove the filename from FilePath altogether)

Example Usage:

string myPath = @"C:\Users\Coder\Documents\Code\Project\File.cs";
var pathInfo = new PathInfo(myPath);

//We can flip all the separators if we want
pathInfo.ConformSeparatorTo('/');

//Remove the filename (strip it back to directory only)
pathInfo.SetFileName("");

pathInfo.AddChunks(true, "src", "Controllers");
pathInfo.SetFileName("FileNameController.cs");

// Value of pathInfo.FilePath is now 
// "C:\Users\Coder\Documents\Code\Project\src\Controllers\FileNameController.cs"

string remotePath = "https://files.example/Coder/Documents/";
string newPath = PathMatcher.Resituate(pathInfo.FilePath, remotePath);

// After "resituating" into remotePath, value of newPath is
// "https://files.example/Coder/Documents/Code/Project/src/Controllers/FileNameController.cs";

PathMatcher

PathMatcher is a static class with utilites which operate on string paths to do special things.

PathMatcher.Resituate

This merges together two paths with some degree of common ancestry to let you, for example, move a local file into the appropriate path on a remote server:

string localPath = @"C:\Users\Alice\Documents\Codes\OpenSource\Project\README.md";
string destinationPath = @"https://filestore.cloud.example/Alice/";
string newRemotePath = PathMatcher.Resituate(localPath, destinationPath);

-> https://filestore.cloud.example/Alice/Documents/Codes/OpenSource/Project/README.md

See PathMatcherTests for more info.

See also design-notes.md

Contributing

To contribute, please open an issue first, where we'd love to discuss the library with you!

License (MIT)

See License.txt

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 netcoreapp1.0 was computed.  netcoreapp1.1 was computed.  netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard1.3 is compatible.  netstandard1.4 was computed.  netstandard1.5 was computed.  netstandard1.6 was computed.  netstandard2.0 was computed.  netstandard2.1 was computed. 
.NET Framework net45 is compatible.  net451 was computed.  net452 was computed.  net46 was computed.  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 tizen30 was computed.  tizen40 was computed.  tizen60 was computed. 
Universal Windows Platform uap was computed.  uap10.0 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.

This package has no dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.2.1 876 2/12/2018
1.0.1 975 1/17/2018

New feature to safely add path chunks