FullPath Struct

Represents an absolute file or directory path with convenient path manipulation methods.

public readonly struct FullPath : IComparable, IComparable<FullPath>, IEquatable<FullPath>

Example

// Create FullPath
FullPath rootPath = FullPath.FromPath("demo");
FullPath filePath = rootPath / "temp" / "file.txt";

// Compare paths (case-insensitive on Windows, macOS, iOS and tvOS, case-sensitive elsewhere)
Assert.False(filePath == rootPath);
Assert.True(filePath.Parent.Parent == rootPath);

// Get relative path (temp\file.txt on Windows, temp/file.txt elsewhere)
string relativePath = filePath.MakePathRelativeTo(rootPath);
Assert.Equal(Path.Combine("temp", "file.txt"), relativePath);
Implements

Properties

NameDescription
EmptyGets an empty FullPath.
ExtensionGets the file extension including the leading dot.
IsEmptyGets a value indicating whether this path is empty.
NameGets the file or directory name and extension.
NameWithoutExtensionGets the file or directory name without the extension.
ParentGets the parent directory of this path, or FullPath.Empty if there is no parent.
RawValueGets the string representation of the path without any conversion, or an empty string if the path is empty.
ValueGets the string representation of the path, or an empty string if the path is empty.

Gets an empty FullPath.

public static FullPath Empty { get; }

Property value

FullPath

Extension

FullPath.cs

Gets the file extension including the leading dot.

public string Extension { get; }

Property value

string

Gets a value indicating whether this path is empty.

public bool IsEmpty { get; }

Property value

bool

Gets the file or directory name and extension.

public string Name { get; }

Property value

string

NameWithoutExtension

FullPath.cs

Gets the file or directory name without the extension.

public string NameWithoutExtension { get; }

Property value

string

Gets the parent directory of this path, or FullPath.Empty if there is no parent.

public FullPath Parent { get; }

Property value

FullPath

RawValue

FullPath.cs

Gets the string representation of the path without any conversion, or an empty string if the path is empty.

public string RawValue { get; }

Property value

string

Remarks

Unlike FullPath.Value, this property returns the path exactly as stored internally, without applying any protection for Windows reserved device names.

Use this property when you need the raw path for operations that handle reserved device names themselves, or when you're certain the path doesn't contain reserved device names.

Gets the string representation of the path, or an empty string if the path is empty.

public string Value { get; }

Property value

string

Remarks

If the path contains a reserved device name (CON, PRN, AUX, NUL, COM0-COM9, COM¹-COM³, LPT0-LPT9, LPT¹-LPT³), the extended path format (\\?\) is returned to bypass Win32 namespace restrictions.

Use FullPath.RawValue if you need the unmodified path without device name protection.

Methods

NameDescription
ChangeExtension(string?)
Combine(FullPath, ReadOnlySpan<string>)Combines a FullPath with a span of relative paths.
Combine(FullPath, string)Combines a FullPath with a relative path.
Combine(FullPath, string, string)Combines a FullPath with two relative paths.
Combine(FullPath, string, string, string)Combines a FullPath with three relative paths.
Combine(FullPath, string[])Combines a FullPath with multiple relative paths.
Combine(ReadOnlySpan<string>)Combines a span of path strings into a full path.
Combine(string, string)Combines two path strings into a full path.
Combine(string, string, string)Combines three path strings into a full path.
Combine(string, string, string, string)Combines four path strings into a full path.
Combine(string[])Combines an array of path strings into a full path.
CompareTo(FullPath)Compares this path to another using the default comparer for the current operating system.
CompareTo(FullPath, bool)Compares this path to another with optional case-insensitive comparison.
CreateParentDirectory()Creates the parent directory of this path if it doesn't exist.
CreateTempFile()Creates a uniquely named, zero-byte temporary file and returns its full path.
CreateTempFile(FullPath?, string?, string?)Creates a uniquely named, zero-byte temporary file and returns its full path.
CreateTempFile(string?, string?)Creates a uniquely named, zero-byte temporary file and returns its full path.
CurrentDirectory()Gets the current working directory.
Equals(FullPath)
Equals(FullPath, bool)Determines whether this path equals another path with optional case-insensitive comparison.
Equals(object?)
FindRequiredGitRepositoryRoot()Finds the first ancestor path or self that contains a Git repository.
FromFileSystemInfo(FileSystemInfo?)Creates a FullPath from a FileSystemInfo object.
FromPath(string)Creates a FullPath from a string path by converting it to an absolute path.
GetFolderPath(Environment.SpecialFolder)Gets the path to the system special folder identified by the specified enumeration.
GetFolderPath(Environment.SpecialFolder, Environment.SpecialFolderOption)Gets the path to the system special folder identified by the specified enumeration.
GetHashCode()
GetHashCode(bool)Returns a hash code for this path with optional case-insensitive comparison.
GetKnownFolderPath(KnownFolder)Gets the path to a Windows known folder.
GetTempFileName()
GetTempPath()Gets the path of the system's temporary folder.
IsChildOf(FullPath)Determines whether this path is a child of the specified root path.
IsSymbolicLink()Determines whether this path represents a symbolic link.
MakePathRelativeTo(FullPath)Creates a relative path from this path to the specified root path.
OpenInExplorer()Opens the system file manager and selects this file or directory.
System.IComparable.CompareTo(object?)
ToString()
ToWindowsExtendedPath()Converts this path to Windows extended-length path format (\\?\).
TryFindFirstAncestor(Func<FullPath, bool>, FullPath)Finds the first ancestor path (excluding self) that matches the specified predicate.
TryFindFirstAncestorOrSelf(Func<FullPath, bool>, FullPath)Finds the first ancestor path or self that matches the specified predicate.
TryFindGitRepositoryRoot(FullPath)Finds the first ancestor path or self that contains a Git repository.
TryGetCanonicalPath(FullPath?)Attempts to resolve this path to its canonical final existing path.
TryGetSymbolicLinkTarget(SymbolicLinkResolutionMode, FullPath?)Attempts to get the target of a symbolic link using the specified resolution mode.
TryGetSymbolicLinkTarget(FullPath?)Attempts to get the immediate target of a symbolic link.
WithExtension(string?)Returns a new path with the specified file extension.
WithExtension(string?, bool)Returns a new path with the specified file extension, optionally replacing all trailing extensions.
WithExtension(string?, int)Returns a new path with the specified file extension, replacing a specific number of trailing extensions.
WithName(string)Returns a new path with the specified name, keeping the same parent directory.
WithNameWithoutExtension(string)Returns a new path with the specified name, keeping the same parent directory but without changing the extension.

ChangeExtension(string?)

FullPath.cs
public FullPath ChangeExtension(string? extension)

Parameters

extension string?

Returns

FullPath

No documentation is available.

Combine overloads

Combine(FullPath, ReadOnlySpan<string>)

FullPath.cs

Combines a FullPath with a span of relative paths.

public static FullPath Combine(FullPath rootPath, params scoped ReadOnlySpan<string> paths)
Parameters
rootPath FullPath
paths ReadOnlySpan<string>
Returns

FullPath

Combine(FullPath, string)

FullPath.cs

Combines a FullPath with a relative path.

public static FullPath Combine(FullPath rootPath, string relativePath)
Parameters
rootPath FullPath
relativePath string
Returns

FullPath

Combine(FullPath, string, string)

FullPath.cs

Combines a FullPath with two relative paths.

public static FullPath Combine(FullPath rootPath, string path1, string path2)
Parameters
rootPath FullPath
path1 string
path2 string
Returns

FullPath

Combine(FullPath, string, string, string)

FullPath.cs

Combines a FullPath with three relative paths.

public static FullPath Combine(FullPath rootPath, string path1, string path2, string path3)
Parameters
rootPath FullPath
path1 string
path2 string
path3 string
Returns

FullPath

Combine(FullPath, string[])

FullPath.cs

Combines a FullPath with multiple relative paths.

public static FullPath Combine(FullPath rootPath, params string[] paths)
Parameters
rootPath FullPath
paths string[]
Returns

FullPath

Combine(ReadOnlySpan<string>)

FullPath.cs

Combines a span of path strings into a full path.

public static FullPath Combine(params scoped ReadOnlySpan<string> paths)
Parameters
paths ReadOnlySpan<string>
Returns

FullPath

Combine(string, string)

FullPath.cs

Combines two path strings into a full path.

public static FullPath Combine(string rootPath, string relativePath)
Parameters
rootPath string
relativePath string
Returns

FullPath

Combine(string, string, string)

FullPath.cs

Combines three path strings into a full path.

public static FullPath Combine(string rootPath, string path1, string path2)
Parameters
rootPath string
path1 string
path2 string
Returns

FullPath

Combine(string, string, string, string)

FullPath.cs

Combines four path strings into a full path.

public static FullPath Combine(string rootPath, string path1, string path2, string path3)
Parameters
rootPath string
path1 string
path2 string
path3 string
Returns

FullPath

Combine(string[])

FullPath.cs

Combines an array of path strings into a full path.

public static FullPath Combine(params string[] paths)
Parameters
paths string[]
Returns

FullPath

CompareTo overloads

CompareTo(FullPath)

FullPath.cs

Compares this path to another using the default comparer for the current operating system.

public int CompareTo(FullPath other)
Parameters
other FullPath
Returns

int

CompareTo(FullPath, bool)

FullPath.cs

Compares this path to another with optional case-insensitive comparison.

public int CompareTo(FullPath other, bool ignoreCase)
Parameters
other FullPath
ignoreCase bool
Returns

int

CreateParentDirectory()

FullPath.cs

Creates the parent directory of this path if it doesn't exist.

public void CreateParentDirectory()

CreateTempFile overloads

CreateTempFile()

FullPath.cs

Creates a uniquely named, zero-byte temporary file and returns its full path.

public static FullPath CreateTempFile()
Returns

FullPath

CreateTempFile(FullPath?, string?, string?)

FullPath.cs

Creates a uniquely named, zero-byte temporary file and returns its full path.

public static FullPath CreateTempFile(FullPath? folder, string? prefix, string? suffix = ".tmp")
Parameters
folder FullPath?
The destination folder. If null or empty, the system temporary folder is used.
prefix string?
A prefix to prepend to the generated file name.
suffix string?
A suffix to append to the generated file name. Defaults to .tmp.
Returns

FullPath

Exceptions
ArgumentException
Thrown when prefix or suffix contains a character that is not valid in a file name, such as a directory separator.
IOException
Thrown when a unique file could not be created after 10 attempts.

CreateTempFile(string?, string?)

FullPath.cs

Creates a uniquely named, zero-byte temporary file and returns its full path.

public static FullPath CreateTempFile(string? prefix, string? suffix = ".tmp")
Parameters
prefix string?
A prefix to prepend to the generated file name.
suffix string?
A suffix to append to the generated file name. Defaults to .tmp.
Returns

FullPath

Exceptions
ArgumentException
Thrown when prefix or suffix contains a character that is not valid in a file name, such as a directory separator.
IOException
Thrown when a unique file could not be created after 10 attempts.

CurrentDirectory()

FullPath.cs

Gets the current working directory.

public static FullPath CurrentDirectory()

Returns

FullPath

Equals overloads

Equals(FullPath)

FullPath.cs
public bool Equals(FullPath other)
Parameters
other FullPath
Returns

bool

No documentation is available.

Equals(FullPath, bool)

FullPath.cs

Determines whether this path equals another path with optional case-insensitive comparison.

public bool Equals(FullPath other, bool ignoreCase)
Parameters
other FullPath
ignoreCase bool
Returns

bool

Equals(object?)

FullPath.cs
public override bool Equals(object? obj)
Parameters
obj object?
Returns

bool

No documentation is available.

FindRequiredGitRepositoryRoot()

FullPath.cs

Finds the first ancestor path or self that contains a Git repository.

public FullPath FindRequiredGitRepositoryRoot()

Returns

FullPath The first matching path.

Exceptions

InvalidOperationException
The Git repository cannot be found.

FromFileSystemInfo(FileSystemInfo?)

FullPath.cs

Creates a FullPath from a FileSystemInfo object.

public static FullPath FromFileSystemInfo(FileSystemInfo? fsi)

Parameters

fsi FileSystemInfo?

Returns

FullPath

FromPath(string)

FullPath.cs

Creates a FullPath from a string path by converting it to an absolute path.

public static FullPath FromPath(string path)

Parameters

path string
The path to convert. Can be relative or absolute. An empty string returns FullPath.Empty.

Returns

FullPath

GetFolderPath overloads

GetFolderPath(Environment.SpecialFolder)

FullPath.cs

Gets the path to the system special folder identified by the specified enumeration.

public static FullPath GetFolderPath(Environment.SpecialFolder folder)
Parameters
folder Environment.SpecialFolder
The special folder to retrieve the path for.
Returns

FullPath

GetFolderPath(Environment.SpecialFolder, Environment.SpecialFolderOption)

FullPath.cs

Gets the path to the system special folder identified by the specified enumeration.

public static FullPath GetFolderPath(Environment.SpecialFolder folder, Environment.SpecialFolderOption option)
Parameters
folder Environment.SpecialFolder
The special folder to retrieve the path for.
option Environment.SpecialFolderOption
Specifies whether the folder must be verified or created.
Returns

FullPath

GetHashCode overloads

GetHashCode()

FullPath.cs
public override int GetHashCode()
Returns

int

No documentation is available.

GetHashCode(bool)

FullPath.cs

Returns a hash code for this path with optional case-insensitive comparison.

public int GetHashCode(bool ignoreCase)
Parameters
ignoreCase bool
Returns

int

GetKnownFolderPath(KnownFolder)

FullPath.cs
  • Supported on windows6.0.6000

Gets the path to a Windows known folder.

[SupportedOSPlatform("windows6.0.6000")]
public static FullPath GetKnownFolderPath(KnownFolder knownFolder)

Parameters

knownFolder KnownFolder
The known folder to retrieve the path for.

Returns

FullPath

GetTempFileName()

FullPath.cs
public static FullPath GetTempFileName()

Returns

FullPath

No documentation is available.

GetTempPath()

FullPath.cs

Gets the path of the system's temporary folder.

public static FullPath GetTempPath()

Returns

FullPath

IsChildOf(FullPath)

FullPath.cs

Determines whether this path is a child of the specified root path.

public bool IsChildOf(FullPath rootPath)

Parameters

rootPath FullPath
The root path to check against.

Returns

bool true if this path is a child of the root path; otherwise, false.

Remarks

The comparison uses the same case sensitivity as FullPathComparer.Default.

MakePathRelativeTo(FullPath)

FullPath.cs

Creates a relative path from this path to the specified root path.

public string MakePathRelativeTo(FullPath rootPath)

Parameters

rootPath FullPath
The root path to make this path relative to.

Returns

string A relative path string, or "." when both paths are equal.

OpenInExplorer()

FullPath.cs
  • Supported on macos
  • Supported on windows5.1.2600

Opens the system file manager and selects this file or directory.

[SupportedOSPlatform("macos")]
[SupportedOSPlatform("windows5.1.2600")]
public void OpenInExplorer()

System.IComparable.CompareTo(object?)

FullPath.cs
int IComparable.CompareTo(object? obj)

Parameters

obj object?

Returns

int

No documentation is available.

ToString()

FullPath.cs
public override string ToString()

Returns

string

No documentation is available.

ToWindowsExtendedPath()

FullPath.cs
  • Supported on windows

Converts this path to Windows extended-length path format (\\?\).

[SupportedOSPlatform("windows")]
public string ToWindowsExtendedPath()

Returns

string The path in extended-length format, or an empty string if the path is empty.

Exceptions

PlatformNotSupportedException
The current operating system is not Windows.

Remarks

The extended-length path format bypasses most path parsing and validation, allowing paths longer than 260 characters.

UNC paths are converted to \\?\UNC\server\share format.

If the path already uses a device path syntax (\\?\, \\.\, or \??\), it is returned as-is.

TryFindFirstAncestor(Func<FullPath, bool>, FullPath)

FullPath.cs

Finds the first ancestor path (excluding self) that matches the specified predicate.

public bool TryFindFirstAncestor(Func<FullPath, bool> predicate, out FullPath result)

Parameters

predicate Func<FullPath, bool>
A function to test each ancestor path.
result FullPath
The first matching ancestor path, or default if not found.

Returns

bool true if a matching ancestor is found; otherwise, false.

TryFindFirstAncestorOrSelf(Func<FullPath, bool>, FullPath)

FullPath.cs

Finds the first ancestor path or self that matches the specified predicate.

public bool TryFindFirstAncestorOrSelf(Func<FullPath, bool> predicate, out FullPath result)

Parameters

predicate Func<FullPath, bool>
A function to test each path.
result FullPath
The first matching path, or default if not found.

Returns

bool true if a matching path is found; otherwise, false.

TryFindGitRepositoryRoot(FullPath)

FullPath.cs

Finds the first ancestor path or self that contains a Git repository.

public bool TryFindGitRepositoryRoot(out FullPath result)

Parameters

result FullPath
The first matching path, or default if not found.

Returns

bool true if a Git repository is found; otherwise, false.

TryGetCanonicalPath(FullPath?)

FullPath.cs

Attempts to resolve this path to its canonical final existing path.

public bool TryGetCanonicalPath(out FullPath? result)

Parameters

result FullPath?
The canonical final path if successful; otherwise, null.

Returns

bool true if canonical resolution succeeds; otherwise, false.

Remarks

The canonical path resolves symbolic links and reparse points to the final target.

This method returns false when the path does not exist or cannot be resolved.

TryGetSymbolicLinkTarget overloads

TryGetSymbolicLinkTarget(SymbolicLinkResolutionMode, FullPath?)

FullPath.cs

Attempts to get the target of a symbolic link using the specified resolution mode.

public bool TryGetSymbolicLinkTarget(SymbolicLinkResolutionMode resolutionMode, out FullPath? result)
Parameters
resolutionMode SymbolicLinkResolutionMode
The mode to use when resolving symbolic links.
result FullPath?
The target path if this is a symbolic link; otherwise, null.
Returns

bool true if this is a symbolic link; otherwise, false.

Exceptions
IOException
A symbolic link chain is too deep to resolve, which usually means the links form a cycle.

TryGetSymbolicLinkTarget(FullPath?)

FullPath.cs

Attempts to get the immediate target of a symbolic link.

public bool TryGetSymbolicLinkTarget(out FullPath? result)
Parameters
result FullPath?
The target path if this is a symbolic link; otherwise, null.
Returns

bool true if this is a symbolic link; otherwise, false.

WithExtension overloads

WithExtension(string?)

FullPath.cs

Returns a new path with the specified file extension.

public FullPath WithExtension(string? extension)
Parameters
extension string?
The new extension (with or without the leading dot), or null to remove the extension.
Returns

FullPath

WithExtension(string?, bool)

FullPath.cs

Returns a new path with the specified file extension, optionally replacing all trailing extensions.

public FullPath WithExtension(string? extension, bool replaceAllTrailingExtensions)
Parameters
extension string?
The new extension (with or without the leading dot), or null to remove the extension. An empty string sets an empty extension, which leaves a trailing dot.
replaceAllTrailingExtensions bool
true to replace all trailing extensions; false to replace only the last extension.
Returns

FullPath A new FullPath instance with the specified extension changes.

WithExtension(string?, int)

FullPath.cs

Returns a new path with the specified file extension, replacing a specific number of trailing extensions.

public FullPath WithExtension(string? extension, int extensionCount)
Parameters
extension string?
The new extension (with or without the leading dot), or null to remove the extension. An empty string sets an empty extension, which leaves a trailing dot.
extensionCount int
The number of trailing extensions to replace. Must be greater than 0.
Returns

FullPath A new FullPath instance with the specified extension changes.

Remarks

Every removal follows Path.ChangeExtension, so a trailing dot is an empty extension that costs one removal, and extensionCount only changes how many of them are removed.

WithName(string)

FullPath.cs

Returns a new path with the specified name, keeping the same parent directory.

public FullPath WithName(string name)

Parameters

name string
The new name for the path.

Returns

FullPath A new FullPath instance with the specified name.

Remarks

If the current path is empty, the returned path will also be empty.

WithNameWithoutExtension(string)

FullPath.cs

Returns a new path with the specified name, keeping the same parent directory but without changing the extension.

public FullPath WithNameWithoutExtension(string nameWithoutExtension)

Parameters

nameWithoutExtension string
The new name for the path, without the extension.

Returns

FullPath A new FullPath instance with the specified name.

Remarks

If the current path is empty, the returned path will also be empty.

Operators

NameDescription
operator +(FullPath, string)Combines a root path with a path using the + operator, ensuring that string concatenation occurs before FullPath concatenation.
operator /(FullPath, string)Combines a root path with a relative path using the / operator.
operator ==(FullPath, FullPath)
operator >(FullPath, FullPath)
operator >=(FullPath, FullPath)
implicit operator string(FullPath)Implicitly converts a FullPath to a String.
operator !=(FullPath, FullPath)
operator <(FullPath, FullPath)
operator <=(FullPath, FullPath)

operator +(FullPath, string)

FullPath.cs

Combines a root path with a path using the + operator, ensuring that string concatenation occurs before FullPath concatenation.

public static FullPath operator +(FullPath rootPath, string suffix)

Parameters

rootPath FullPath
suffix string

Returns

FullPath

operator /(FullPath, string)

FullPath.cs

Combines a root path with a relative path using the / operator.

public static FullPath operator /(FullPath rootPath, string relativePath)

Parameters

rootPath FullPath
relativePath string

Returns

FullPath

operator ==(FullPath, FullPath)

FullPath.cs
public static bool operator ==(FullPath path1, FullPath path2)

Parameters

path1 FullPath
path2 FullPath

Returns

bool

No documentation is available.

operator >(FullPath, FullPath)

FullPath.cs
public static bool operator >(FullPath path1, FullPath path2)

Parameters

path1 FullPath
path2 FullPath

Returns

bool

No documentation is available.

operator >=(FullPath, FullPath)

FullPath.cs
public static bool operator >=(FullPath path1, FullPath path2)

Parameters

path1 FullPath
path2 FullPath

Returns

bool

No documentation is available.

implicit operator string(FullPath)

FullPath.cs

Implicitly converts a FullPath to a String.

public static implicit operator string(FullPath fullPath)

Parameters

fullPath FullPath

Returns

string

operator !=(FullPath, FullPath)

FullPath.cs
public static bool operator !=(FullPath path1, FullPath path2)

Parameters

path1 FullPath
path2 FullPath

Returns

bool

No documentation is available.

operator <(FullPath, FullPath)

FullPath.cs
public static bool operator <(FullPath path1, FullPath path2)

Parameters

path1 FullPath
path2 FullPath

Returns

bool

No documentation is available.

operator <=(FullPath, FullPath)

FullPath.cs
public static bool operator <=(FullPath path1, FullPath path2)

Parameters

path1 FullPath
path2 FullPath

Returns

bool

No documentation is available.