Class PathExtensions
- Namespace
- TruePath
- Assembly
- TruePath.dll
Extension methods for IPath and IPath<TPath>.
public static class PathExtensions
- Inheritance
-
PathExtensions
- Inherited Members
Methods
GetExtensionWithDot(IPath)
Gets the extension of the file name of the path
with the dot character.
For example, for the path file.txt
, this method will return a string .txt
.
File name entirely consisting of extension, such as .gitignore
, is returned as-is.
public static string GetExtensionWithDot(this IPath path)
Parameters
path
IPath
Returns
- string
The extension of the file name of the path with the dot character (if present).
Remarks
This method will return an empty string for paths without extensions, and will return a dot for paths whose names end with a dot (even though it is an unusual path). This behavior allows to distinguish such paths, and potentially reconstruct the file name from its part without the extension and the "extension with dot".
GetExtensionWithoutDot(IPath)
Gets the extension of the file name of the path
without the dot character.
For example, for the path file.txt
, this method will return a string txt
.
File name entirely consisting of extension, such as .gitignore
, is returned with its leading dot
trimmed.
public static string GetExtensionWithoutDot(this IPath path)
Parameters
path
IPath
Returns
- string
The extension of the file name of the path without the dot.
Remarks
This method will return an empty string for paths without extensions and with empty extensions (ending with dot, which may be unusual). This behavior doesn't allow to distinguish such paths using this method, to reconstruct the original name from its name without extension and its extension without dot.
GetFilenameWithoutExtension(IPath)
Gets the file name of the path
without the extension.
For example, for the path file.txt
, this method will return a string file
.
public static string GetFilenameWithoutExtension(this IPath path)
Parameters
path
IPath
Returns
- string
The file name of the path without the extension. If the path has no extension, the file name is returned as-is (one trailing dot will be stripped, though).
WithExtension<TPath>(TPath, string?)
Returns a new path of the same type TPath
with the extension of its file name component changed,
or with a new extension-like component if the original file name was empty.
public static TPath WithExtension<TPath>(this TPath path, string? extension) where TPath : IPath<TPath>
Parameters
path
TPathThe original path.
extension
stringThe new extension to apply.
Returns
- TPath
A new path of type
TPath
with the modified file name component. The originalpath
object is not modified.
Type Parameters
TPath
The type of the path, which must implement IPath<TPath>.