You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Pathy is a tiny source-only library that will allow you to build file and directory paths by chaining together strings like `"c:"`, `"dir1"`, `"dir2"` using
42
+
Pathy is a tiny source-only library that will allow you to build file and directory paths by chaining together strings like `"c:"`, `"dir1"`, `"dir2"` using
43
43
44
-
`ChainablePath.New() / "c:" / "dir1" / "dir2"`.
44
+
`ChainablePath.New() / "c:" / "dir1" / "dir2"`.
45
45
46
46
It was heavily inspired by the best build pipeline framework available in the .NET space, [Nuke](https://nuke.build/). Nuke has supported these concepts for many years, but I needed this capability outside build pipelines. Lots of kudos to [Matthias Koch](https://www.linkedin.com/in/matthias-koch-jb/) for what I see as a brilliant idea.
47
47
48
-
It doesn't have any dependencies and runs on .NET 4.7, .NET 8, as well as frameworks supporting .NET Standard 2.0 and 2.1.
48
+
It doesn't have any dependencies and runs on .NET 4.7, .NET 8, as well as frameworks supporting .NET Standard 2.0 and 2.1.
49
49
50
50
### What's so special about that?
51
51
52
-
It makes those chained calls to `Path.Combine` a thing from the past and hides the ugliness of dealing with (trailing) slashes.
52
+
It makes those chained calls to `Path.Combine` a thing from the past and hides the ugliness of dealing with (trailing) slashes.
53
53
54
-
It ships as a source-only package, which means you can use it in your own libraries and projects, without incurring any dependency pain on your consuming projects.
54
+
It ships as a source-only package, which means you can use it in your own libraries and projects, without incurring any dependency pain on your consuming projects.
55
55
56
56
The core Pathy package does not have any dependencies, and I purposely moved the [globbing](https://learn.microsoft.com/en-us/dotnet/core/extensions/file-globbing#pattern-formats) functionality into a separate package as it depends on `Microsoft.Extensions.FileSystemGlobbing`.
57
57
@@ -69,7 +69,7 @@ This library is available as [a NuGet package](https://www.nuget.org/packages/Pa
69
69
## How do I use it?
70
70
71
71
### To ChainablePath and back to string
72
-
It all starts with the construction of a `ChainablePath` instance to represent a path to a file or directory.
72
+
It all starts with the construction of a `ChainablePath` instance to represent a path to a file or directory.
73
73
74
74
There are several ways of doing that.
75
75
@@ -80,11 +80,11 @@ var path = "c:/mypath/to/a/directory".ToPath();
Additionally, you can use `ChainablePath.Current` to get the current working directory as an instance of `ChainablePath`, and `ChainablePath.Temp` to get that for the user's temporary folder.
83
+
Additionally, you can use `ChainablePath.Current` to get the current working directory as an instance of `ChainablePath`, and `ChainablePath.Temp` to get that for the user's temporary folder.
84
84
85
-
The first thing you'll notice is how the `/` operator is used to chain multiple parts of a path together. This is the primary feature of Pathy. And it doesn't matter if you do that on Linux or Windows. Internally it'll use whatever path separator is suitable.
85
+
The first thing you'll notice is how the `/` operator is used to chain multiple parts of a path together. This is the primary feature of Pathy. And it doesn't matter if you do that on Linux or Windows. Internally it'll use whatever path separator is suitable.
86
86
87
-
You can also use the `+` operator to add some phrase to the path _without_ using a separator.
87
+
You can also use the `+` operator to add some phrase to the path _without_ using a separator.
To convert an instance of `ChainablePath` back to a `string`, you can either call `ToString()` or cast the instance to a `string`.
98
+
To convert an instance of `ChainablePath` back to a `string`, you can either call `ToString()` or cast the instance to a `string`.
99
99
100
100
```csharp
101
101
stringrawPath=path.ToString();
@@ -108,10 +108,11 @@ Know that `ChainablePath` overrides `Equals` and `GetHashCode`, so you can alway
108
108
109
109
Given an instance of `ChainablePath`, you can get a lot of useful information:
110
110
*`Name` returns the full name, but without the directory, whereas `Extension` gives you the extension _including_ the dot.
111
-
*`Directory`, `Parent` or `DirectoryName` give you the (parent) directory of a file or directory.
111
+
*`Directory`, `Parent` or `DirectoryName` give you the (parent) directory of a file or directory.
112
112
* To see if a path is absolute, use `IsRooted`
113
113
* Not sure if a path points to an actual file system entry? Use `IsFile`, `IsDirectory` or `Exists`
114
114
* Want to know the delta between two paths? Use `AsRelativeTo`.
115
+
* To determine if a file has a case-insensitive extension, use `HasExtension(".txt")` or `HasExtension("txt")`.
115
116
116
117
And if the built-in functionality really isn't enough, you can always call `ToDirectoryInfo` or `ToFileInfo` to continue with an instance of `DirectoryInfo` and `FileInfo`.
0 commit comments