Class RootedPath
- Namespace
- Invex.FileSystem
- Assembly
- Invex.FileSystem.dll
Represents a file system path that is rooted within a specific System.IO.Abstractions.IFileSystem instance.
public record RootedPath
- Inheritance
-
objectRootedPath
Remarks
Properties such as FileName and DirectoryName intentionally
return null when the path does not match the expected entry type (file vs. directory),
rather than throwing, so callers can use null-coalescing patterns naturally. The existence
checks never throw: FileExists is true only for an existing
file, DirectoryExists only for an existing directory, and
PathExists for either.
Constructors
RootedPath(IFileSystem, string)
Represents a file system path that is rooted within a specific System.IO.Abstractions.IFileSystem instance.
public RootedPath(IFileSystem FileSystem, string Path)
Parameters
FileSystemIFileSystemThe file system instance this path belongs to.
PathstringThe absolute path string.
Remarks
Properties such as FileName and DirectoryName intentionally
return null when the path does not match the expected entry type (file vs. directory),
rather than throwing, so callers can use null-coalescing patterns naturally. The existence
checks never throw: FileExists is true only for an existing
file, DirectoryExists only for an existing directory, and
PathExists for either.
Properties
DirectoryExists
Indicates whether the path exists in the file system as a directory.
public bool DirectoryExists { get; }
Property Value
- bool
DirectoryName
Gets the path of the directory containing the current path, as computed by System.IO.Abstractions.IPath.GetDirectoryName(string).
public string? DirectoryName { get; }
Property Value
- string
The containing directory's path if the current path resolves to an existing directory; otherwise
null. Returnsnull(rather than throwing) when the path points to a file or does not exist.
Remarks
System.IO.Abstractions.IPath.GetDirectoryName(string) strips the last path segment and any trailing separator — it returns the parent path, not the directory's own name. For the last segment of the path itself, use FileNameWithoutExtension.
FileExists
Indicates whether the path exists in the file system as a file.
public bool FileExists { get; }
Property Value
- bool
FileName
Gets the file name (including extension) from the current path.
public string? FileName { get; }
Property Value
- string
The file name if the path resolves to an existing file; otherwise
null. Returnsnull(rather than throwing) when the path points to a directory or does not exist, so callers can safely use null-coalescing without a prior existence check.
FileNameWithoutExtension
Gets the file name of the current path without its extension.
public string FileNameWithoutExtension { get; }
Property Value
- string
Remarks
Unlike FileName, this property does not check whether the file exists — it is a pure path-string operation and always returns a value.
FileSystem
The file system instance this path belongs to.
public IFileSystem FileSystem { get; init; }
Property Value
- IFileSystem
Parent
Gets the parent directory of the current path.
public RootedPath? Parent { get; }
Property Value
- RootedPath
A new RootedPath representing the parent directory, or
nullif the current path is already a root.
Remarks
A trailing directory separator on the input path is stripped before the parent is computed
so that /foo/ and /foo both yield the same parent (/).
The returned path always ends with System.IO.Abstractions.IPath.DirectorySeparatorChar so it can be
combined further with the / operator without producing double separators.
Path
The absolute path string.
public string Path { get; init; }
Property Value
- string
PathExists
Indicates whether the path exists in the file system as either a file or a directory.
public bool PathExists { get; }
Property Value
- bool
Remarks
Equivalent to FileExists || DirectoryExists.
Methods
ToString()
public override string ToString()
Returns
- string
Operators
operator /(RootedPath, string)
Combines the current RootedPath with a relative string segment using System.IO.Abstractions.IPath.Combine(string, string).
public static RootedPath operator /(RootedPath left, string right)
Parameters
leftRootedPathThe base RootedPath.
rightstringThe relative segment to append.
Returns
- RootedPath
A new RootedPath representing the combined path.
Remarks
Using an operator instead of a method keeps path-construction code concise and readable,
e.g. rootedFileSystem.GetPath("Root") / "src" / "MyProject".
The operator preserves the original FileSystem reference so the resulting
path remains bound to the same file-system abstraction.
implicit operator string(RootedPath)
Implicitly converts a RootedPath to its string representation.
public static implicit operator string(RootedPath path)
Parameters
pathRootedPathThe RootedPath to convert.
Returns
- string
The string representation of the path.
Remarks
Allows a RootedPath to be passed directly to any API that accepts a
string path without an explicit cast or .ToString() call.