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);Properties
| Name | Description |
|---|---|
| Empty | Gets an empty FullPath. |
| Extension | Gets the file extension including the leading dot. |
| IsEmpty | Gets a value indicating whether this path is empty. |
| Name | Gets the file or directory name and extension. |
| NameWithoutExtension | Gets the file or directory name without the extension. |
| Parent | Gets the parent directory of this path, or FullPath.Empty if there is no parent. |
| RawValue | Gets the string representation of the path without any conversion, or an empty string if the path is empty. |
| Value | Gets the string representation of the path, or an empty string if the path is empty. |
Empty
FullPath.csExtension
FullPath.csIsEmpty
FullPath.csName
FullPath.csNameWithoutExtension
FullPath.csParent
FullPath.csGets the parent directory of this path, or FullPath.Empty if there is no parent.
public FullPath Parent { get; }Property value
RawValue
FullPath.csGets the string representation of the path without any conversion, or an empty string if the path is empty.
public string RawValue { get; }Property value
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.
Value
FullPath.csGets the string representation of the path, or an empty string if the path is empty.
public string Value { get; }Property value
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
| Name | Description |
|---|---|
| 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.csCombine overloads
Combine(FullPath, ReadOnlySpan<string>)
FullPath.csCombines a FullPath with a span of relative paths.
public static FullPath Combine(FullPath rootPath, params scoped ReadOnlySpan<string> paths)Combine(FullPath, string)
FullPath.csCombine(FullPath, string, string)
FullPath.csCombine(FullPath, string, string, string)
FullPath.csCombine(FullPath, string[])
FullPath.csCombine(ReadOnlySpan<string>)
FullPath.csCombines a span of path strings into a full path.
public static FullPath Combine(params scoped ReadOnlySpan<string> paths)Combine(string, string)
FullPath.csCombine(string, string, string)
FullPath.csCombine(string, string, string, string)
FullPath.csCombine(string[])
FullPath.csCreateParentDirectory()
FullPath.csCreates the parent directory of this path if it doesn't exist.
public void CreateParentDirectory()CreateTempFile overloads
CreateTempFile()
FullPath.csCreateTempFile(FullPath?, string?, string?)
FullPath.csCreates a uniquely named, zero-byte temporary file and returns its full path.
Parameters
folderFullPath?- The destination folder. If
nullor empty, the system temporary folder is used. prefixstring?- A prefix to prepend to the generated file name.
suffixstring?- A suffix to append to the generated file name. Defaults to
.tmp.
Returns
Exceptions
ArgumentException- Thrown when
prefixorsuffixcontains 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.csCreates a uniquely named, zero-byte temporary file and returns its full path.
Parameters
prefixstring?- A prefix to prepend to the generated file name.
suffixstring?- A suffix to append to the generated file name. Defaults to
.tmp.
Returns
Exceptions
ArgumentException- Thrown when
prefixorsuffixcontains 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.csEquals overloads
Equals(FullPath)
FullPath.csEquals(FullPath, bool)
FullPath.csEquals(object?)
FullPath.csFindRequiredGitRepositoryRoot()
FullPath.csFinds 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.csCreates a FullPath from a FileSystemInfo object.
public static FullPath FromFileSystemInfo(FileSystemInfo? fsi)FromPath(string)
FullPath.csGetFolderPath overloads
GetFolderPath(Environment.SpecialFolder)
FullPath.csGets the path to the system special folder identified by the specified enumeration.
public static FullPath GetFolderPath(Environment.SpecialFolder folder)GetFolderPath(Environment.SpecialFolder, Environment.SpecialFolderOption)
FullPath.csGets the path to the system special folder identified by the specified enumeration.
public static FullPath GetFolderPath(Environment.SpecialFolder folder, Environment.SpecialFolderOption option)Parameters
folderEnvironment.SpecialFolder- The special folder to retrieve the path for.
optionEnvironment.SpecialFolderOption- Specifies whether the folder must be verified or created.
Returns
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)GetTempFileName()
FullPath.csGetTempPath()
FullPath.csIsChildOf(FullPath)
FullPath.csDetermines whether this path is a child of the specified root path.
Parameters
rootPathFullPath- 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.
IsSymbolicLink()
FullPath.csMakePathRelativeTo(FullPath)
FullPath.csOpenInExplorer()
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.csToString()
FullPath.csToWindowsExtendedPath()
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.csFinds the first ancestor path (excluding self) that matches the specified predicate.
Parameters
predicateFunc<FullPath, bool>- A function to test each ancestor path.
resultFullPath- 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.csFinds the first ancestor path or self that matches the specified predicate.
Parameters
predicateFunc<FullPath, bool>- A function to test each path.
resultFullPath- The first matching path, or default if not found.
Returns
bool true if a matching path is found; otherwise, false.
TryFindGitRepositoryRoot(FullPath)
FullPath.csTryGetCanonicalPath(FullPath?)
FullPath.csAttempts to resolve this path to its canonical final existing path.
Parameters
resultFullPath?- 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.csAttempts to get the target of a symbolic link using the specified resolution mode.
public bool TryGetSymbolicLinkTarget(SymbolicLinkResolutionMode resolutionMode, out FullPath? result)Parameters
resolutionModeSymbolicLinkResolutionMode- The mode to use when resolving symbolic links.
resultFullPath?- 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.csWithExtension overloads
WithExtension(string?)
FullPath.csWithExtension(string?, bool)
FullPath.csReturns a new path with the specified file extension, optionally replacing all trailing extensions.
Parameters
extensionstring?- The new extension (with or without the leading dot), or
nullto remove the extension. An empty string sets an empty extension, which leaves a trailing dot. replaceAllTrailingExtensionsbooltrueto replace all trailing extensions;falseto replace only the last extension.
Returns
FullPath A new FullPath instance with the specified extension changes.
WithExtension(string?, int)
FullPath.csReturns a new path with the specified file extension, replacing a specific number of trailing extensions.
Parameters
extensionstring?- The new extension (with or without the leading dot), or
nullto remove the extension. An empty string sets an empty extension, which leaves a trailing dot. extensionCountint- 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.csReturns a new path with the specified name, keeping the same parent directory.
WithNameWithoutExtension(string)
FullPath.csReturns a new path with the specified name, keeping the same parent directory but without changing the extension.
Operators
| Name | Description |
|---|---|
| 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) |