Table of Contents

Struct AbsolutePath

Namespace
TruePath
Assembly
TruePath.dll

This is a path on the local system that's guaranteed to be absolute: that is, path that is rooted and has a disk letter (on Windows).

public readonly struct AbsolutePath : IEquatable<AbsolutePath>, IPath, IPath<AbsolutePath>
Implements
Inherited Members
Extension Methods

Remarks

For a path that's not guaranteed to be absolute, use the LocalPath type.

Constructors

AbsolutePath(string)

Creates an AbsolutePath instance by normalizing the path from the passed string according to the rules stated in LocalPath.

public AbsolutePath(string value)

Parameters

value string

Path string to normalize.

Exceptions

ArgumentException

Thrown if the passed string does not represent an absolute path.

AbsolutePath(LocalPath)

Creates an AbsolutePath instance by converting a localPath object.

public AbsolutePath(LocalPath localPath)

Parameters

localPath LocalPath

Exceptions

ArgumentException

Thrown if the passed path is not absolute.

Fields

PlatformDefaultComparer

Provides a default comparer for comparing file paths, aware of the current platform.

On Windows and macOS, this will perform case-insensitive string comparison, since the file systems are case-insensitive on these operating systems by default.

On Linux, the comparison will be case-sensitive.

public static readonly IEqualityComparer<AbsolutePath> PlatformDefaultComparer

Field Value

IEqualityComparer<AbsolutePath>

Remarks

Note that this comparison does not guarantee correctness: in practice, on any platform to control case-sensitiveness of either the whole file system or a part of it. This class does not take this into account, having a benefit of no accessing the file system for any of the comparisons.

StrictStringComparer

A strict comparer for comparing file paths using ordinal, case-sensitive comparison of the underlying path strings.

public static readonly IEqualityComparer<AbsolutePath> StrictStringComparer

Field Value

IEqualityComparer<AbsolutePath>

Properties

CurrentWorkingDirectory

Gets the current working directory as an AbsolutePath instance.

public static AbsolutePath CurrentWorkingDirectory { get; }

Property Value

AbsolutePath

The current working directory.

FileName

The name of the last component of this path.

public string FileName { get; }

Property Value

string

Parent

The parent of this path. Will be null for a rooted absolute path. For a relative path, will always resolve to its parent directory — by either removing directories from the end of the path, or appending

..
to the end.
public AbsolutePath? Parent { get; }

Property Value

AbsolutePath?

Value

The normalized path string.

public string Value { get; }

Property Value

string

Methods

Canonicalize()

Corrects the file name case on case-insensitive file systems, resolves symlinks.

public AbsolutePath Canonicalize()

Returns

AbsolutePath

Equals(object?)

Compares the path with another.

public override bool Equals(object? obj)

Parameters

obj object

Returns

bool

Remarks

Note that currently this comparison is case-sensitive.

Equals(AbsolutePath)

Compares the path with another.

public bool Equals(AbsolutePath other)

Parameters

other AbsolutePath

Returns

bool

Remarks

Note that currently this comparison is case-sensitive.

Equals(AbsolutePath, IEqualityComparer<AbsolutePath>)

Determines whether the specified AbsolutePath is equal to the current AbsolutePath using the specified comparer.

public bool Equals(AbsolutePath other, IEqualityComparer<AbsolutePath> comparer)

Parameters

other AbsolutePath

The AbsolutePath to compare with the current AbsolutePath.

comparer IEqualityComparer<AbsolutePath>

The comparer to use for comparing the paths. For example, pass PlatformDefaultComparer or StrictStringComparer.

Returns

bool

true if the specified AbsolutePath is equal to the current AbsolutePath using the specified comparer; otherwise, false.

GetHashCode()

Serves as the default hash function.

public override int GetHashCode()

Returns

int

A hash code for the current object.

IsPrefixOf(AbsolutePath)

public bool IsPrefixOf(AbsolutePath other)

Parameters

other AbsolutePath

Returns

bool

Remarks

Checks for a non-strict prefix: if the paths are equal then they are still considered prefixes of each other.

ReadKind()

Determines the type of the file system entry (file, directory, symlink, or junction) for the given path.

public FileEntryKind? ReadKind()

Returns

FileEntryKind?

A FileEntryKind enumeration value representing the type of the file system entry, or null if the entry does not exist.

Remarks

This method checks if the specified path represents a file, directory, symbolic link, or junction. On Windows, it uses IsJunction(string) to identify junctions and checks for the ReparsePoint flag to identify symbolic links.

RelativeTo(AbsolutePath)

Calculates the relative path from a base path to this path.

public LocalPath RelativeTo(AbsolutePath basePath)

Parameters

basePath AbsolutePath

The base path from which to calculate the relative path.

Returns

LocalPath

The relative path from the base path to this path.

StartsWith(AbsolutePath)

Determines whether the current path starts with the specified path.

public bool StartsWith(AbsolutePath other)

Parameters

other AbsolutePath

The path to compare to the current path.

Returns

bool

Remarks

Note that currently this comparison is case-sensitive.

ToString()

public override string ToString()

Returns

string

The normalized path string contained in this object.

Operators

operator /(AbsolutePath, string)

public static AbsolutePath operator /(AbsolutePath basePath, string b)

Parameters

basePath AbsolutePath
b string

Returns

AbsolutePath

Remarks

Note that in case path b is absolute, it will completely take over and the basePath will be ignored.

operator /(AbsolutePath, LocalPath)

public static AbsolutePath operator /(AbsolutePath basePath, LocalPath b)

Parameters

basePath AbsolutePath
b LocalPath

Returns

AbsolutePath

Remarks

Note that in case path b is absolute, it will completely take over and the basePath will be ignored.

operator ==(AbsolutePath, AbsolutePath)

Compares the path with another.

public static bool operator ==(AbsolutePath left, AbsolutePath right)

Parameters

left AbsolutePath
right AbsolutePath

Returns

bool

Remarks

Note that currently this comparison is case-sensitive.

operator !=(AbsolutePath, AbsolutePath)

Compares the path with another.

public static bool operator !=(AbsolutePath left, AbsolutePath right)

Parameters

left AbsolutePath
right AbsolutePath

Returns

bool

Remarks

Note that currently this comparison is case-sensitive.