Table of Contents

Class PathIo

Namespace
TruePath.SystemIo
Assembly
TruePath.SystemIo.dll

Extension methods for the AbsolutePath type that provide common I/O operations.

public static class PathIo
Inheritance
PathIo
Inherited Members

Methods

AppendAllLines(AbsolutePath, IEnumerable<string>)

Appends the specified lines to the file, creating the file if it does not already exist.

public static void AppendAllLines(this AbsolutePath path, IEnumerable<string> contents)

Parameters

path AbsolutePath

The file to append to.

contents IEnumerable<string>

The lines to write to the file.

Remarks

Given a sequence of strings and a file path, this method opens the specified file, appends the each string as a line to the end of the file using the specified encoding, and then closes the file. The file handle is guaranteed to be closed by this method, even if exceptions are raised. The method creates the file if it doesn't exist, but it doesn't create new directories. Therefore, the value of the path parameter must contain existing directories.

Exceptions

ArgumentNullException

path is null.

ArgumentException

path is empty.

PathTooLongException

The specified path, file name, or both exceed the system-defined maximum length.

DirectoryNotFoundException

The specified path is invalid (for example, it is on an unmapped drive).

IOException

An I/O error occurred while opening the file.

UnauthorizedAccessException

path specified a file that is read-only.

UnauthorizedAccessException

path specified a file that is hidden.

UnauthorizedAccessException

path specified a directory.

UnauthorizedAccessException

This operation is not supported on the current platform.

UnauthorizedAccessException

The caller does not have the required permission.

NotSupportedException

path is in an invalid format.

AppendAllLines(AbsolutePath, IEnumerable<string>, Encoding)

Appends the specified lines to the file, creating the file if it does not already exist.

public static void AppendAllLines(this AbsolutePath path, IEnumerable<string> contents, Encoding encoding)

Parameters

path AbsolutePath

The file to append to.

contents IEnumerable<string>

The lines to write to the file.

encoding Encoding

The encoding to apply to the each line.

Remarks

Given a sequence of strings and a file path, this method opens the specified file, appends the each string as a line to the end of the file using the specified encoding, and then closes the file. The file handle is guaranteed to be closed by this method, even if exceptions are raised. The method creates the file if it doesn't exist, but it doesn't create new directories. Therefore, the value of the path parameter must contain existing directories.

Exceptions

ArgumentNullException

path is null.

ArgumentException

path is empty.

ArgumentNullException

encoding is null.

PathTooLongException

The specified path, file name, or both exceed the system-defined maximum length.

DirectoryNotFoundException

The specified path is invalid (for example, it is on an unmapped drive).

IOException

An I/O error occurred while opening the file.

UnauthorizedAccessException

path specified a file that is read-only.

UnauthorizedAccessException

path specified a file that is hidden.

UnauthorizedAccessException

path specified a directory.

UnauthorizedAccessException

This operation is not supported on the current platform.

UnauthorizedAccessException

The caller does not have the required permission.

NotSupportedException

path is in an invalid format.

AppendAllLinesAsync(AbsolutePath, IEnumerable<string>, Encoding, CancellationToken)

Asynchronously appends the specified lines to the file, creating the file if it does not already exist.

public static Task AppendAllLinesAsync(this AbsolutePath path, IEnumerable<string> contents, Encoding encoding, CancellationToken cancellationToken = default)

Parameters

path AbsolutePath

The file to append to.

contents IEnumerable<string>

The lines to write to the file.

encoding Encoding

The encoding to apply to the each line.

cancellationToken CancellationToken

The token to monitor for cancellation requests. The default value is None.

Returns

Task

A task that represents the asynchronous append operation.

Remarks

Given a sequence of strings and a file path, this method opens the specified file, appends the each string as a line to the end of the file using the specified encoding, and then closes the file. The file handle is guaranteed to be closed by this method, even if exceptions are raised. The method creates the file if it doesn't exist, but it doesn't create new directories. Therefore, the value of the path parameter must contain existing directories.

Exceptions

ArgumentNullException

path is null.

ArgumentException

path is empty.

ArgumentNullException

encoding is null.

PathTooLongException

The specified path, file name, or both exceed the system-defined maximum length.

DirectoryNotFoundException

The specified path is invalid (for example, it is on an unmapped drive).

IOException

An I/O error occurred while opening the file.

UnauthorizedAccessException

path specified a file that is read-only.

UnauthorizedAccessException

path specified a file that is hidden.

UnauthorizedAccessException

path specified a directory.

UnauthorizedAccessException

This operation is not supported on the current platform.

UnauthorizedAccessException

The caller does not have the required permission.

NotSupportedException

path is in an invalid format.

AppendAllLinesAsync(AbsolutePath, IEnumerable<string>, CancellationToken)

Asynchronously appends the specified lines to the file, creating the file if it does not already exist.

public static Task AppendAllLinesAsync(this AbsolutePath path, IEnumerable<string> contents, CancellationToken cancellationToken = default)

Parameters

path AbsolutePath

The file to append to.

contents IEnumerable<string>

The lines to write to the file.

cancellationToken CancellationToken

The token to monitor for cancellation requests. The default value is None.

Returns

Task

A task that represents the asynchronous append operation.

Remarks

Given a sequence of strings and a file path, this method opens the specified file, appends the each string as a line to the end of the file using the specified encoding, and then closes the file. The file handle is guaranteed to be closed by this method, even if exceptions are raised. The method creates the file if it doesn't exist, but it doesn't create new directories. Therefore, the value of the path parameter must contain existing directories.

Exceptions

ArgumentNullException

path is null.

ArgumentException

path is empty.

PathTooLongException

The specified path, file name, or both exceed the system-defined maximum length.

DirectoryNotFoundException

The specified path is invalid (for example, it is on an unmapped drive).

IOException

An I/O error occurred while opening the file.

UnauthorizedAccessException

path specified a file that is read-only.

UnauthorizedAccessException

path specified a file that is hidden.

UnauthorizedAccessException

path specified a directory.

UnauthorizedAccessException

This operation is not supported on the current platform.

UnauthorizedAccessException

The caller does not have the required permission.

NotSupportedException

path is in an invalid format.

AppendAllText(AbsolutePath, string?)

Appends the specified string to the file, creating the file if it does not already exist.

public static void AppendAllText(this AbsolutePath path, string? contents)

Parameters

path AbsolutePath

The file to append to.

contents string

The characters to write to the file.

Remarks

Given a string and a file path, this method opens the specified file, appends the string to the end of the file using the specified encoding, and then closes the file. The file handle is guaranteed to be closed by this method, even if exceptions are raised. The method creates the file if it doesn't exist, but it doesn't create new directories. Therefore, the value of the path parameter must contain existing directories.

Exceptions

ArgumentNullException

path is null.

ArgumentException

path is empty.

PathTooLongException

The specified path, file name, or both exceed the system-defined maximum length.

DirectoryNotFoundException

The specified path is invalid (for example, it is on an unmapped drive).

IOException

An I/O error occurred while opening the file.

UnauthorizedAccessException

path specified a file that is read-only.

UnauthorizedAccessException

path specified a file that is hidden.

UnauthorizedAccessException

path specified a directory.

UnauthorizedAccessException

This operation is not supported on the current platform.

UnauthorizedAccessException

The caller does not have the required permission.

NotSupportedException

path is in an invalid format.

AppendAllText(AbsolutePath, string?, Encoding)

Appends the specified string to the file, creating the file if it does not already exist.

public static void AppendAllText(this AbsolutePath path, string? contents, Encoding encoding)

Parameters

path AbsolutePath

The file to append to.

contents string

The characters to write to the file.

encoding Encoding

The encoding to apply to the string.

Remarks

Given a string and a file path, this method opens the specified file, appends the string to the end of the file using the specified encoding, and then closes the file. The file handle is guaranteed to be closed by this method, even if exceptions are raised. The method creates the file if it doesn't exist, but it doesn't create new directories. Therefore, the value of the path parameter must contain existing directories.

Exceptions

ArgumentNullException

path is null.

ArgumentException

path is empty.

ArgumentNullException

encoding is null.

PathTooLongException

The specified path, file name, or both exceed the system-defined maximum length.

DirectoryNotFoundException

The specified path is invalid (for example, it is on an unmapped drive).

IOException

An I/O error occurred while opening the file.

UnauthorizedAccessException

path specified a file that is read-only.

UnauthorizedAccessException

path specified a file that is hidden.

UnauthorizedAccessException

path specified a directory.

UnauthorizedAccessException

This operation is not supported on the current platform.

UnauthorizedAccessException

The caller does not have the required permission.

NotSupportedException

path is in an invalid format.

AppendAllTextAsync(AbsolutePath, string?, Encoding, CancellationToken)

Asynchronously appends the specified string to the file, creating the file if it does not already exist.

public static Task AppendAllTextAsync(this AbsolutePath path, string? contents, Encoding encoding, CancellationToken cancellationToken = default)

Parameters

path AbsolutePath

The file to append to.

contents string

The characters to write to the file.

encoding Encoding

The encoding to apply to the string.

cancellationToken CancellationToken

The token to monitor for cancellation requests. The default value is None.

Returns

Task

A task that represents the asynchronous append operation.

Remarks

Given a string and a file path, this method opens the specified file, appends the string to the end of the file using the specified encoding, and then closes the file. The file handle is guaranteed to be closed by this method, even if exceptions are raised. The method creates the file if it doesn't exist, but it doesn't create new directories. Therefore, the value of the path parameter must contain existing directories.

Exceptions

ArgumentNullException

path is null.

ArgumentException

path is empty.

ArgumentNullException

encoding is null.

PathTooLongException

The specified path, file name, or both exceed the system-defined maximum length.

DirectoryNotFoundException

The specified path is invalid (for example, it is on an unmapped drive).

IOException

An I/O error occurred while opening the file.

UnauthorizedAccessException

path specified a file that is read-only.

UnauthorizedAccessException

path specified a file that is hidden.

UnauthorizedAccessException

path specified a directory.

UnauthorizedAccessException

This operation is not supported on the current platform.

UnauthorizedAccessException

The caller does not have the required permission.

NotSupportedException

path is in an invalid format.

AppendAllTextAsync(AbsolutePath, string?, CancellationToken)

Asynchronously appends the specified string to the file, creating the file if it does not already exist.

public static Task AppendAllTextAsync(this AbsolutePath path, string? contents, CancellationToken cancellationToken = default)

Parameters

path AbsolutePath

The file to append to.

contents string

The characters to write to the file.

cancellationToken CancellationToken

The token to monitor for cancellation requests. The default value is None.

Returns

Task

A task that represents the asynchronous append operation.

Remarks

Given a string and a file path, this method opens the specified file, appends the string to the end of the file using the specified encoding, and then closes the file. The file handle is guaranteed to be closed by this method, even if exceptions are raised. The method creates the file if it doesn't exist, but it doesn't create new directories. Therefore, the value of the path parameter must contain existing directories.

Exceptions

ArgumentNullException

path is null.

ArgumentException

path is empty.

PathTooLongException

The specified path, file name, or both exceed the system-defined maximum length.

DirectoryNotFoundException

The specified path is invalid (for example, it is on an unmapped drive).

IOException

An I/O error occurred while opening the file.

UnauthorizedAccessException

path specified a file that is read-only.

UnauthorizedAccessException

path specified a file that is hidden.

UnauthorizedAccessException

path specified a directory.

UnauthorizedAccessException

This operation is not supported on the current platform.

UnauthorizedAccessException

The caller does not have the required permission.

NotSupportedException

path is in an invalid format.

AppendText(AbsolutePath)

Creates a StreamWriter that appends UTF-8 encoded text to an existing file, or to a new file if the specified file does not exist.

public static StreamWriter AppendText(this AbsolutePath path)

Parameters

path AbsolutePath

The path to the file to append to.

Returns

StreamWriter

A stream writer that appends UTF-8 encoded text to the specified file or to a new file.

Copy(AbsolutePath, AbsolutePath)

Copies an existing file to a new file. Overwriting a file of the same name is not allowed.

public static void Copy(this AbsolutePath sourceFile, AbsolutePath destFile)

Parameters

sourceFile AbsolutePath

The file to copy.

destFile AbsolutePath

The name of the destination file. This cannot be a directory or an existing file.

Copy(AbsolutePath, AbsolutePath, bool)

Copies an existing file to a new file. Overwriting a file of the same name is allowed.

public static void Copy(this AbsolutePath sourceFile, AbsolutePath destFile, bool overwrite)

Parameters

sourceFile AbsolutePath

The file to copy.

destFile AbsolutePath

The name of the destination file. This cannot be a directory.

overwrite bool

true if the destination file should be replaced if it already exists; otherwise, false.

Create(AbsolutePath)

Creates, or truncates and overwrites, a file in the specified path.

public static FileStream Create(this AbsolutePath path)

Parameters

path AbsolutePath

The path and name of the file to create.

Returns

FileStream

A FileStream that provides read/write access to the file specified in path.

Create(AbsolutePath, int)

Creates, or truncates and overwrites, a file in the specified path, specifying a buffer size.

public static FileStream Create(this AbsolutePath path, int bufferSize)

Parameters

path AbsolutePath

The path and name of the file to create.

bufferSize int

The number of bytes buffered for reads and writes to the file.

Returns

FileStream

A FileStream that provides read/write access to the file specified in path.

Create(AbsolutePath, int, FileOptions)

Creates or overwrites a file in the specified path, specifying a buffer size and options that describe how to create or overwrite the file.

public static FileStream Create(this AbsolutePath path, int bufferSize, FileOptions options)

Parameters

path AbsolutePath

The path and name of the file to create.

bufferSize int

The number of bytes buffered for reads and writes to the file.

options FileOptions

One of the FileOptions values that describes how to create or overwrite the file.

Returns

FileStream

A FileStream that provides read/write access to the file specified in path.

CreateDirectory(AbsolutePath)

Creates all directories and subdirectories in the specified path unless they already exist.

public static void CreateDirectory(AbsolutePath path)

Parameters

path AbsolutePath

The directory to create.

CreateText(AbsolutePath)

Creates or opens a file for writing UTF-8 encoded text. If the file already exists, its contents are replaced.

public static StreamWriter CreateText(this AbsolutePath path)

Parameters

path AbsolutePath

The file to be opened for writing.

Returns

StreamWriter

A StreamWriter that writes to the specified file using UTF-8 encoding.

Delete(AbsolutePath)

Deletes the specified file or directory.

public static void Delete(this AbsolutePath path)

Parameters

path AbsolutePath

The name of the file to be deleted. Wildcard characters are not supported.

DeleteDirectoryRecursively(AbsolutePath)

Deletes the specified directory and any subdirectories and files in the directory.

public static void DeleteDirectoryRecursively(AbsolutePath path)

Parameters

path AbsolutePath

The name of the directory to remove. This directory must be writable.

DeleteEmptyDirectory(AbsolutePath)

Deletes the specified empty directory.

public static void DeleteEmptyDirectory(AbsolutePath path)

Parameters

path AbsolutePath

The name of the directory to remove. This directory must be writable and empty.

Exists(AbsolutePath)

Determines whether the specified file exists.

public static bool Exists(this AbsolutePath path)

Parameters

path AbsolutePath

The file to check.

Returns

bool

true if the caller has the required permissions and path contains the name of an existing file; otherwise, false. This method also returns false if path is null, an invalid path, or a zero-length string. If the caller does not have sufficient permissions to read the specified file, no exception is thrown and the method returns false regardless of the existence of path.

ExistsDirectory(AbsolutePath)

Determines whether the given path refers to an existing directory on disk.

public static bool ExistsDirectory(this AbsolutePath path)

Parameters

path AbsolutePath

The path to test.

Returns

bool

true if path refers to an existing directory; false if the directory does not exist or an error occurs when trying to determine if the specified directory exists.

GetAttributes(AbsolutePath)

Gets the FileAttributes of the file on the path.

public static FileAttributes GetAttributes(this AbsolutePath path)

Parameters

path AbsolutePath

The path to the file.

Returns

FileAttributes

The FileAttributes of the file on the path.

GetCreationTime(AbsolutePath)

Returns the creation date and time of the specified file or directory.

public static DateTime GetCreationTime(this AbsolutePath path)

Parameters

path AbsolutePath

The file or directory for which to obtain creation date and time information.

Returns

DateTime

A DateTime structure set to the creation date and time for the specified file or directory. This value is expressed in local time.

GetCreationTimeUtc(AbsolutePath)

Returns the creation date and time, in Coordinated Universal Time (UTC), of the specified file or directory.

public static DateTime GetCreationTimeUtc(this AbsolutePath path)

Parameters

path AbsolutePath

The file or directory for which to obtain creation date and time information.

Returns

DateTime

A DateTime structure set to the creation date and time for the specified file or directory. This value is expressed in UTC time.

GetLastAccessTime(AbsolutePath)

Returns the date and time the specified file or directory was last accessed.

public static DateTime GetLastAccessTime(this AbsolutePath path)

Parameters

path AbsolutePath

The file or directory for which to obtain access date and time information.

Returns

DateTime

A DateTime structure set to the date and time that the specified file or directory was last accessed. This value is expressed in local time.

GetLastAccessTimeUtc(AbsolutePath)

Returns the date and time, in Coordinated Universal Time (UTC), that the specified file or directory was last accessed.

public static DateTime GetLastAccessTimeUtc(this AbsolutePath path)

Parameters

path AbsolutePath

The file or directory for which to obtain access date and time information.

Returns

DateTime

A DateTime structure set to the date and time that the specified file or directory was last accessed. This value is expressed in UTC time.

GetLastWriteTime(AbsolutePath)

Returns the date and time the specified file or directory was last written to.

public static DateTime GetLastWriteTime(this AbsolutePath path)

Parameters

path AbsolutePath

The file or directory for which to obtain write date and time information.

Returns

DateTime

A DateTime structure set to the date and time that the specified file or directory was last written to. This value is expressed in local time.

GetLastWriteTimeUtc(AbsolutePath)

Returns the date and time, in Coordinated Universal Time (UTC), that the specified file or directory was last written to.

public static DateTime GetLastWriteTimeUtc(this AbsolutePath path)

Parameters

path AbsolutePath

The file or directory for which to obtain write date and time information.

Returns

DateTime

A DateTime structure set to the date and time that the specified file or directory was last written to. This value is expressed in UTC time.

GetUnixFileMode(AbsolutePath)

Gets the UnixFileMode of the file on the path.

public static UnixFileMode GetUnixFileMode(this AbsolutePath path)

Parameters

path AbsolutePath

The path to the file.

Returns

UnixFileMode

The UnixFileMode of the file on the path.

Move(AbsolutePath, AbsolutePath)

Moves a specified file to a new location, providing the option to specify a new file name.

public static void Move(this AbsolutePath sourceFile, AbsolutePath destFile)

Parameters

sourceFile AbsolutePath

The name of the file to move. Can include a relative or absolute path.

destFile AbsolutePath

The new path and name for the file.

Move(AbsolutePath, AbsolutePath, bool)

Moves a specified file to a new location, providing the options to specify a new file name and to replace the destination file if it already exists.

public static void Move(this AbsolutePath sourceFile, AbsolutePath destFile, bool overwrite)

Parameters

sourceFile AbsolutePath

The name of the file to move. Can include a relative or absolute path.

destFile AbsolutePath

The new path and name for the file.

overwrite bool

true to replace the destination file if it already exists; false otherwise.

Open(AbsolutePath, FileMode)

Opens a FileStream on the specified path with read/write access with no sharing.

public static FileStream Open(this AbsolutePath path, FileMode mode)

Parameters

path AbsolutePath

The file to open.

mode FileMode

A FileMode value that specifies whether a file is created if one does not exist, and determines whether the contents of existing files are retained or overwritten.

Returns

FileStream

A FileStream opened in the specified mode and path, with read/write access and not shared.

Open(AbsolutePath, FileMode, FileAccess)

Opens a FileStream on the specified path with the specified mode and access with no sharing.

public static FileStream Open(this AbsolutePath path, FileMode mode, FileAccess access)

Parameters

path AbsolutePath

The file to open.

mode FileMode

A FileMode value that specifies whether a file is created if one does not exist, and determines whether the contents of existing files are retained or overwritten.

access FileAccess

A FileAccess value that specifies the operations that can be performed on the file.

Returns

FileStream

A FileStream opened in the specified mode and path, with the specified mode and access with no sharing.

Open(AbsolutePath, FileMode, FileAccess, FileShare)

Opens a FileStream on the specified path, having the specified mode with read, write, or read/write access and the specified sharing option.

public static FileStream Open(this AbsolutePath path, FileMode mode, FileAccess access, FileShare share)

Parameters

path AbsolutePath

The file to open.

mode FileMode

A FileMode value that specifies whether a file is created if one does not exist, and determines whether the contents of existing files are retained or overwritten.

access FileAccess

A FileAccess value that specifies the operations that can be performed on the file.

share FileShare

A FileShare value specifying the type of access other threads have to the file.

Returns

FileStream

A FileStream on the specified path, having the specified mode with read, write, or read/write access and the specified sharing option.

OpenRead(AbsolutePath)

Opens an existing file for reading.

public static FileStream OpenRead(this AbsolutePath path)

Parameters

path AbsolutePath

The file to be opened for reading.

Returns

FileStream

A read-only FileStream on the specified path.

OpenText(AbsolutePath)

Opens an existing UTF-8 encoded text file for reading.

public static StreamReader OpenText(this AbsolutePath path)

Parameters

path AbsolutePath

The file to be opened for reading.

Returns

StreamReader

A StreamReader on the specified path.

OpenWrite(AbsolutePath)

Opens an existing file or creates a new file for writing.

public static FileStream OpenWrite(this AbsolutePath path)

Parameters

path AbsolutePath

The file to be opened for writing.

Returns

FileStream

An unshared FileStream object on the specified path with Write access.

ReadAllBytes(AbsolutePath)

Opens a binary file, reads the contents of the file into a byte array, and then closes the file.

public static byte[] ReadAllBytes(this AbsolutePath path)

Parameters

path AbsolutePath

The file to open for reading.

Returns

byte[]

A byte array containing the contents of the file.

ReadAllBytesAsync(AbsolutePath, CancellationToken)

Asynchronously opens a binary file, reads the contents of the file into a byte array, and then closes the file.

public static Task<byte[]> ReadAllBytesAsync(this AbsolutePath path, CancellationToken cancellationToken = default)

Parameters

path AbsolutePath

The file to open for reading.

cancellationToken CancellationToken

The token to monitor for cancellation requests. The default value is None.

Returns

Task<byte[]>

A task that represents the asynchronous read operation, which wraps the byte array containing the contents of the file.

ReadAllLines(AbsolutePath)

Opens a text file, reads all lines of the file, and then closes the file.

public static string[] ReadAllLines(this AbsolutePath path)

Parameters

path AbsolutePath

The file to open for reading.

Returns

string[]

A string array containing all lines of the file.

ReadAllLines(AbsolutePath, Encoding)

Opens a file, reads all lines of the file with the specified encoding, and then closes the file.

public static string[] ReadAllLines(this AbsolutePath path, Encoding encoding)

Parameters

path AbsolutePath

The file to open for reading.

encoding Encoding

The encoding applied to the contents of the file.

Returns

string[]

A string array containing all lines of the file.

ReadLines(AbsolutePath)

Reads the lines of a file.

public static IEnumerable<string> ReadLines(this AbsolutePath path)

Parameters

path AbsolutePath

The file to read.

Returns

IEnumerable<string>

All the lines of the file, or the lines that are the result of a query.

ReadLines(AbsolutePath, Encoding)

Read the lines of a file that has a specified encoding.

public static IEnumerable<string> ReadLines(this AbsolutePath path, Encoding encoding)

Parameters

path AbsolutePath

The file to read.

encoding Encoding

The encoding that is applied to the contents of the file.

Returns

IEnumerable<string>

All the lines of the file, or the lines that are the result of a query.

ReadLinesAsync(AbsolutePath, Encoding, CancellationToken)

Asynchronously reads the lines of a file that has a specified encoding.

public static IAsyncEnumerable<string> ReadLinesAsync(this AbsolutePath path, Encoding encoding, CancellationToken cancellationToken = default)

Parameters

path AbsolutePath

The file to read.

encoding Encoding

The encoding that is applied to the contents of the file.

cancellationToken CancellationToken

The token to monitor for cancellation requests. The default value is None.

Returns

IAsyncEnumerable<string>

The async enumerable that represents all the lines of the file, or the lines that are the result of a query.

ReadLinesAsync(AbsolutePath, CancellationToken)

Asynchronously reads the lines of a file.

public static IAsyncEnumerable<string> ReadLinesAsync(this AbsolutePath path, CancellationToken cancellationToken = default)

Parameters

path AbsolutePath

The file to read.

cancellationToken CancellationToken

The token to monitor for cancellation requests. The default value is None.

Returns

IAsyncEnumerable<string>

The async enumerable that represents all the lines of the file, or the lines that are the result of a query.

SetAttributes(AbsolutePath, FileAttributes)

Sets the specified FileAttributes of the file on the specified path.

public static void SetAttributes(this AbsolutePath path, FileAttributes fileAttributes)

Parameters

path AbsolutePath

The path to the file.

fileAttributes FileAttributes

A bitwise combination of the enumeration values.

SetCreationTime(AbsolutePath, DateTime)

Sets the date and time the file was created.

public static void SetCreationTime(this AbsolutePath path, DateTime creationTime)

Parameters

path AbsolutePath

The file for which to set the creation date and time information.

creationTime DateTime

A DateTime containing the value to set for the creation date and time of path. This value is expressed in local time.

SetCreationTimeUtc(AbsolutePath, DateTime)

Sets the date and time, in Coordinated Universal Time (UTC), that the file was created.

public static void SetCreationTimeUtc(this AbsolutePath path, DateTime creationTimeUtc)

Parameters

path AbsolutePath

The file for which to set the creation date and time information.

creationTimeUtc DateTime

The value to set for the creation date and time of path. This value is expressed in UTC time.

SetLastAccessTime(AbsolutePath, DateTime)

Sets the date and time the specified file was last accessed.

public static void SetLastAccessTime(this AbsolutePath path, DateTime lastAccessTime)

Parameters

path AbsolutePath

The file for which to set the access date and time information.

lastAccessTime DateTime

A DateTime containing the value to set for the last access date and time of path. This value is expressed in local time.

SetLastAccessTimeUtc(AbsolutePath, DateTime)

Sets the date and time, in Coordinated Universal Time (UTC), that the specified file was last accessed.

public static void SetLastAccessTimeUtc(this AbsolutePath path, DateTime lastAccessTimeUtc)

Parameters

path AbsolutePath

The file for which to set the access date and time information.

lastAccessTimeUtc DateTime

A DateTime containing the value to set for the last access date and time of path. This value is expressed in UTC time.

SetLastWriteTime(AbsolutePath, DateTime)

Sets the date and time that the specified file was last written to.

public static void SetLastWriteTime(this AbsolutePath path, DateTime lastWriteTime)

Parameters

path AbsolutePath

The file for which to set the date and time information.

lastWriteTime DateTime

A DateTime containing the value to set for the last write date and time of path. This value is expressed in local time.

SetLastWriteTimeUtc(AbsolutePath, DateTime)

Sets the date and time, in Coordinated Universal Time (UTC), that the specified file was last written to.

public static void SetLastWriteTimeUtc(this AbsolutePath path, DateTime lastWriteTimeUtc)

Parameters

path AbsolutePath

The file for which to set the date and time information.

lastWriteTimeUtc DateTime

A DateTime containing the value to set for the last write date and time of path. This value is expressed in UTC time.

WriteAllBytes(AbsolutePath, byte[])

Creates a new file, writes the specified byte array to the file, and then closes the file. If the target file already exists, it is truncated and overwritten.

public static void WriteAllBytes(this AbsolutePath path, byte[] bytes)

Parameters

path AbsolutePath

The file to write to.

bytes byte[]

The bytes to write to the file.

WriteAllBytesAsync(AbsolutePath, byte[], CancellationToken)

Asynchronously creates a new file, writes the specified byte array to the file, and then closes the file. If the target file already exists, it is truncated and overwritten.

public static Task WriteAllBytesAsync(this AbsolutePath path, byte[] bytes, CancellationToken cancellationToken = default)

Parameters

path AbsolutePath

The file to write to.

bytes byte[]

The bytes to write to the file.

cancellationToken CancellationToken

The token to monitor for cancellation requests. The default value is None.

Returns

Task

A task that represents the asynchronous write operation.

WriteAllLines(AbsolutePath, IEnumerable<string>)

Creates a new file, writes a collection of strings to the file, and then closes the file.

public static void WriteAllLines(this AbsolutePath path, IEnumerable<string> contents)

Parameters

path AbsolutePath

The file to write to.

contents IEnumerable<string>

The lines to write to the file.

WriteAllLines(AbsolutePath, IEnumerable<string>, Encoding)

Creates a new file by using the specified encoding, writes a collection of strings to the file, and then closes the file.

public static void WriteAllLines(this AbsolutePath path, IEnumerable<string> contents, Encoding encoding)

Parameters

path AbsolutePath

The file to write to.

contents IEnumerable<string>

The lines to write to the file.

encoding Encoding

The character encoding to use.

WriteAllLines(AbsolutePath, string[])

Creates a new file, write the specified string array to the file, and then closes the file.

public static void WriteAllLines(this AbsolutePath path, string[] contents)

Parameters

path AbsolutePath

The file to write to.

contents string[]

The string array to write to the file.

WriteAllLines(AbsolutePath, string[], Encoding)

Creates a new file, writes the specified string array to the file by using the specified encoding, and then closes the file.

public static void WriteAllLines(this AbsolutePath path, string[] contents, Encoding encoding)

Parameters

path AbsolutePath

The file to write to.

contents string[]

The string array to write to the file.

encoding Encoding

An Encoding object that represents the character encoding applied to the string array.

WriteAllLinesAsync(AbsolutePath, IEnumerable<string>, Encoding, CancellationToken)

Asynchronously creates a new file, write the specified lines to the file by using the specified encoding, and then closes the file.

public static Task WriteAllLinesAsync(this AbsolutePath path, IEnumerable<string> contents, Encoding encoding, CancellationToken cancellationToken = default)

Parameters

path AbsolutePath

The file to write to.

contents IEnumerable<string>

The lines to write to the file.

encoding Encoding

The character encoding to use.

cancellationToken CancellationToken

The token to monitor for cancellation requests. The default value is None.

Returns

Task

A task that represents the asynchronous write operation.

WriteAllLinesAsync(AbsolutePath, IEnumerable<string>, CancellationToken)

Asynchronously creates a new file, writes the specified lines to the file, and then closes the file.

public static Task WriteAllLinesAsync(this AbsolutePath path, IEnumerable<string> contents, CancellationToken cancellationToken = default)

Parameters

path AbsolutePath

The file to write to.

contents IEnumerable<string>

The lines to write to the file.

cancellationToken CancellationToken

The token to monitor for cancellation requests. The default value is None.

Returns

Task

A task that represents the asynchronous write operation.

WriteAllText(AbsolutePath, string?)

Creates a new file, writes the specified string to the file, and then closes the file. If the target file already exists, it is truncated and overwritten.

public static void WriteAllText(this AbsolutePath path, string? contents)

Parameters

path AbsolutePath

The file to write to.

contents string

The string to write to the file.

WriteAllText(AbsolutePath, string?, Encoding)

Creates a new file, writes the specified string to the file using the specified encoding, and then closes the file. If the target file already exists, it is truncated and overwritten.

public static void WriteAllText(this AbsolutePath path, string? contents, Encoding encoding)

Parameters

path AbsolutePath

The file to write to.

contents string

The string to write to the file.

encoding Encoding

The character encoding to use.

WriteAllTextAsync(AbsolutePath, string?, Encoding, CancellationToken)

Asynchronously creates a new file, writes the specified string to the file using the specified encoding, and then closes the file. If the target file already exists, it is truncated and overwritten.

public static Task WriteAllTextAsync(AbsolutePath path, string? contents, Encoding encoding, CancellationToken cancellationToken = default)

Parameters

path AbsolutePath

The file to write to.

contents string

The string to write to the file.

encoding Encoding

The character encoding to use.

cancellationToken CancellationToken

The token to monitor for cancellation requests. The default value is None.

Returns

Task

A task that represents the asynchronous write operation.

WriteAllTextAsync(AbsolutePath, string?, CancellationToken)

Asynchronously creates a new file, writes the specified string to the file, and then closes the file. If the target file already exists, it is truncated and overwritten.

public static Task WriteAllTextAsync(this AbsolutePath path, string? contents, CancellationToken cancellationToken = default)

Parameters

path AbsolutePath

The file to write to.

contents string

The string to write to the file.

cancellationToken CancellationToken

The token to monitor for cancellation requests. The default value is None.

Returns

Task

A task that represents the asynchronous write operation.