Class AbsolutePath
- Namespace
- DotNetDo
- Assembly
- DotNetDo.Core.dll
An immutable, normalized absolute path with explicit root semantics.
public sealed record AbsolutePath : IEquatable<AbsolutePath>Properties
Exists
Whether a file or directory currently exists at this path.
public bool Exists { get; }Property Value
Extension
The final component's extension, including its leading period; empty when it has none.
public string Extension { get; }Property Value
IsExistingDirectory
Whether an existing directory occupies this path.
public bool IsExistingDirectory { get; }Property Value
IsExistingFile
Whether an existing regular file occupies this path.
public bool IsExistingFile { get; }Property Value
IsRoot
Whether this path contains only its root and no path components.
[MemberNotNullWhen(false, "Name")]
public bool IsRoot { get; }Property Value
Name
The final path component, or null for a root or empty path.
public string? Name { get; }Property Value
NameWithoutExtension
The final component without its last extension; null for a root path.
public string? NameWithoutExtension { get; }Property Value
Parent
The containing path. Accessing this property on a root throws.
public AbsolutePath Parent { get; }Property Value
Root
The Unix, drive, or UNC root of this path.
public AbsolutePath Root { get; }Property Value
UnixPath
Renders the normalized path with forward slashes, regardless of the current platform.
public string UnixPath { get; }Property Value
WindowsPath
Renders the normalized path with backslashes, regardless of the current platform.
public string WindowsPath { get; }Property Value
Methods
CopyInto(AbsolutePath, TransferOptions?)
Copies this item beneath the supplied destination directory using its current name.
public AbsolutePath CopyInto(AbsolutePath directory, TransferOptions? options = null)Parameters
directoryAbsolutePath-
The directory that will contain a copy under this item's current name.
optionsTransferOptions?-
Controls replacement of existing items and creation of missing directories.
Returns
CopyTo(AbsolutePath, TransferOptions?)
Copies this file or directory to the exact destination path.
public AbsolutePath CopyTo(AbsolutePath destination, TransferOptions? options = null)Parameters
destinationAbsolutePath-
The exact destination filename or directory path.
optionsTransferOptions?-
Controls replacement of existing items and creation of missing parent directories.
Returns
Delete()
Deletes the file or directory.
public void Delete()EnsureDirectoryExists()
Creates this directory and any missing parents, returning this path.
public AbsolutePath EnsureDirectoryExists()Returns
Equals(AbsolutePath?)
Compares normalized path structure using ordinal segment equality.
public bool Equals(AbsolutePath? other)Parameters
otherAbsolutePath?
Returns
GetAncestry()
Returns the path and its parents up to and including the root.
public IEnumerable<AbsolutePath> GetAncestry()Returns
GetHashCode()
Serves as the default hash function.
public override int GetHashCode()Returns
- int
-
A hash code for the current object.
GlobDirectories(IEnumerable<string>, GlobOptions?)
Returns directories beneath this directory matched by the ordered include and exclude patterns.
public AbsolutePath[] GlobDirectories(IEnumerable<string> patterns, GlobOptions? options = null)Parameters
patternsIEnumerable<string>-
Ordered directory-relative globs. Exclusions begin with
!and remove earlier matches. optionsGlobOptions?-
Optional glob comparison settings; defaults to ordinal matching.
Returns
GlobDirectories(string, GlobOptions?)
Returns directories beneath this directory matched by the ordered include and exclude patterns.
public AbsolutePath[] GlobDirectories(string pattern, GlobOptions? options = null)Parameters
patternstring-
A glob relative to this directory. Prefix with
!to exclude earlier matches. optionsGlobOptions?-
Optional glob comparison settings; defaults to ordinal matching.
Returns
GlobFiles(IEnumerable<string>, GlobOptions?)
Returns files beneath this directory matched by the ordered include and exclude patterns.
public AbsolutePath[] GlobFiles(IEnumerable<string> patterns, GlobOptions? options = null)Parameters
patternsIEnumerable<string>-
Ordered directory-relative globs. Exclusions begin with
!and remove earlier matches. optionsGlobOptions?-
Optional glob comparison settings; defaults to ordinal matching.
Returns
GlobFiles(string, GlobOptions?)
Returns files beneath this directory matched by the ordered include and exclude patterns.
public AbsolutePath[] GlobFiles(string pattern, GlobOptions? options = null)Parameters
patternstring-
A glob relative to this directory. Prefix with
!to exclude earlier matches. optionsGlobOptions?-
Optional glob comparison settings; defaults to ordinal matching.
Returns
IsWithin(AbsolutePath)
Returns whether this path is equal to or nested beneath the supplied directory.
public bool IsWithin(AbsolutePath directory)Parameters
directoryAbsolutePath-
The candidate ancestor; paths on a different root are never considered ancestors.
Returns
MoveInto(AbsolutePath, TransferOptions?)
Moves this item beneath the supplied destination directory using its current name.
public AbsolutePath MoveInto(AbsolutePath directory, TransferOptions? options = null)Parameters
directoryAbsolutePath-
The directory that will contain this item under its current name.
optionsTransferOptions?-
Controls replacement of existing items and creation of missing directories.
Returns
MoveTo(AbsolutePath, TransferOptions?)
Moves this file or directory to the exact destination path.
public AbsolutePath MoveTo(AbsolutePath destination, TransferOptions? options = null)Parameters
destinationAbsolutePath-
The exact destination filename or directory path.
optionsTransferOptions?-
Controls replacement of existing items and creation of missing parent directories.
Returns
Parse(string)
Normalizes a Unix-rooted, drive-rooted, or UNC-rooted path without accessing the filesystem.
public static AbsolutePath Parse(string path)Parameters
pathstring-
The non-empty absolute path text; may use either directory separator. Relative, drive-relative, NUL-containing, and root-escaping paths are rejected.
Returns
QuotedArgument()
Renders the value as one quoted command-line argument.
public string QuotedArgument()Returns
ReadJson(JsonSerializerOptions?)
Reads the file as a JSON document model.
public JsonNode? ReadJson(JsonSerializerOptions? options = null)Parameters
optionsJsonSerializerOptions?
Returns
ReadJson<T>(JsonSerializerOptions?)
Deserializes the file into the requested value type.
public T? ReadJson<T>(JsonSerializerOptions? options = null)Parameters
optionsJsonSerializerOptions?-
JSON serializer behavior; null uses System.Text.Json.JsonSerializerOptions.Default.
Returns
- T?
Type Parameters
T
ReadLines(Encoding?)
Reads all file lines using the supplied encoding or UTF-8.
public string[] ReadLines(Encoding? encoding = null)Parameters
Returns
- string[]
ReadText(Encoding?)
Reads the entire file as text using the supplied encoding or UTF-8.
public string ReadText(Encoding? encoding = null)Parameters
Returns
ReadToml(TomlSerializerOptions?)
Reads the file as a TOML document model.
public TomlTable ReadToml(TomlSerializerOptions? options = null)Parameters
optionsTomlSerializerOptions?
Returns
- TomlTable
ReadToml<T>(TomlSerializerOptions?)
Deserializes the file into the requested value type.
public T? ReadToml<T>(TomlSerializerOptions? options = null)Parameters
optionsTomlSerializerOptions?-
TOML serializer behavior; null uses Tomlyn defaults.
Returns
- T?
Type Parameters
T
ReadXml()
Reads the file as an XML document model.
public XDocument ReadXml()Returns
ReadXml<T>()
Deserializes the file into the requested value type.
public T? ReadXml<T>()Returns
- T?
Type Parameters
T
ReadYaml()
Reads the root node of one YAML document from the file.
public YamlNode? ReadYaml()Returns
- YamlNode?
ReadYaml<T>(IDeserializer?)
Deserializes one YAML document from the file into the requested value type.
public T? ReadYaml<T>(IDeserializer? deserializer = null)Parameters
deserializerIDeserializer?-
The YAML deserializer; null uses DotNetDo's default instance.
Returns
- T?
Type Parameters
T
RecreateDirectory()
Delete and recreate this directory.
public AbsolutePath RecreateDirectory()Returns
RelativePathTo(AbsolutePath)
Computes the lexical path from this location to another path on the same root.
public RelativePath RelativePathTo(AbsolutePath path)Parameters
pathAbsolutePath-
The destination path. It must use the same Unix, drive, or UNC root as this path.
Returns
TemporaryFileContents(Action<AbsolutePath>)
Temporarily replaces this file's contents and restores its original bytes when disposed.
public IDisposable TemporaryFileContents(Action<AbsolutePath> replace)Parameters
replaceAction<AbsolutePath>-
The operation that replaces this file's contents.
Returns
ToString()
Returns a string that represents the current object.
public override string ToString()Returns
- string
-
A string that represents the current object.
TryParse(string?, out AbsolutePath?)
Tries to normalize a Unix-rooted, drive-rooted, or UNC-rooted path without accessing the filesystem.
public static bool TryParse(string? path, out AbsolutePath? result)Parameters
pathstring?-
The path text; may use either directory separator. null, relative, drive-relative, and NUL-containing paths are invalid.
resultAbsolutePath?-
The normalized absolute path when parsing succeeds; otherwise null.
Returns
UnzipTo(AbsolutePath, UnzipOptions?)
Extracts this ZIP archive into the exact destination directory.
public AbsolutePath UnzipTo(AbsolutePath destination, UnzipOptions? options = null)Parameters
destinationAbsolutePath-
The exact output directory. Its parent directory must exist.
optionsUnzipOptions?-
Controls merging with existing destination entries.
Returns
WriteJson<T>(T, JsonSerializerOptions?)
Serializes the value to this file.
public void WriteJson<T>(T value, JsonSerializerOptions? options = null)Parameters
valueT-
The value serialized as JSON. Missing parent directories are not created.
optionsJsonSerializerOptions?-
JSON serializer behavior; null uses System.Text.Json.JsonSerializerOptions.Default.
Type Parameters
T
WriteLines(IEnumerable<string>, Encoding?)
Writes lines to this existing file location using the supplied encoding or UTF-8.
public void WriteLines(IEnumerable<string> lines, Encoding? encoding = null)Parameters
linesIEnumerable<string>-
The lines to write using the platform newline. Missing parent directories are not created.
encodingEncoding?-
The text encoding; null uses UTF-8.
WriteText(string, Encoding?)
Writes text to this existing file location using the supplied encoding or UTF-8.
public void WriteText(string text, Encoding? encoding = null)Parameters
textstring-
The complete file content. Missing parent directories are not created.
encodingEncoding?-
The text encoding; null uses UTF-8.
WriteToml<T>(T, TomlSerializerOptions?)
Serializes the value to this file.
public void WriteToml<T>(T value, TomlSerializerOptions? options = null)Parameters
valueT-
The value serialized as TOML. Missing parent directories are not created.
optionsTomlSerializerOptions?-
TOML serializer behavior; null uses Tomlyn defaults.
Type Parameters
T
WriteXml(XDocument)
Writes an XML document model to this file.
public void WriteXml(XDocument value)Parameters
valueXDocument
WriteXml<T>(T)
Serializes the value to this file.
public void WriteXml<T>(T value)Parameters
valueT-
The value serialized with System.Xml.Serialization.XmlSerializer. Missing parent directories are not created.
Type Parameters
T
WriteYaml(YamlNode)
Writes one YAML document-model root node to this file.
public void WriteYaml(YamlNode value)Parameters
valueYamlNode
WriteYaml<T>(T, ISerializer?)
Serializes the value as one YAML document to this file.
public void WriteYaml<T>(T value, ISerializer? serializer = null)Parameters
valueT-
The value serialized as YAML. Missing parent directories are not created.
serializerISerializer?-
The YAML serializer; null uses DotNetDo's default instance.
Type Parameters
T
ZipTo(AbsolutePath, ZipOptions?)
Creates a ZIP archive from this file or directory at the exact destination path.
public AbsolutePath ZipTo(AbsolutePath destination, ZipOptions? options = null)Parameters
destinationAbsolutePath-
The exact archive path. Its parent directory must exist.
optionsZipOptions?-
Controls compression and replacement of an existing archive.
Returns
Operators
implicit operator string(AbsolutePath)
Renders the path using the current operating system's directory separator.
public static implicit operator string(AbsolutePath path)Parameters
pathAbsolutePath
Returns
operator /(AbsolutePath, AbsolutePath) Deprecated
The right operand must be relative.
Prevents joining two absolute paths.
[Obsolete("The right operand must be relative.", true)]
public static AbsolutePath operator /(AbsolutePath left, AbsolutePath right)Parameters
leftAbsolutePathrightAbsolutePath
Returns
operator /(AbsolutePath, RelativePath)
Resolves a relative path against an absolute path, rejecting traversal above its root.
public static AbsolutePath operator /(AbsolutePath left, RelativePath right)Parameters
leftAbsolutePath-
The absolute base path.
rightRelativePath-
The relative path to resolve.
Returns
operator /(AbsolutePath, string)
Parses and resolves relative path text against an absolute path.
public static AbsolutePath operator /(AbsolutePath left, string right)Parameters
leftAbsolutePath-
The absolute base path.
rightstring-
Relative path text; rooted, drive-relative, NUL-containing, and root-escaping values are rejected.