ReadWrite

This is the most comprehensive interface, offering complete filesystem operations using Path objects including reading, writing, and path manipulation.

Functions

Link copied to clipboard
open suspend override fun copy(source: Path, target: Path)

Copies a file or directory from source to target. If the source is a directory, all its contents are copied recursively. Parent directories of the target will be created if they don't exist. The operation is performed with Dispatchers.IO context.

Link copied to clipboard
open suspend override fun create(path: Path, type: FileMetadata.FileType)

Creates a new file or directory denoted by the path using the specified type. It is created with Dispatchers.IO context. Parent directories will be created if they don't exist.

Link copied to clipboard

Creates a directory at the specified path. Parent directories will be created automatically if they don't exist.

Link copied to clipboard

Creates a file at the specified path. Parent directories will be created automatically if they don't exist.

Link copied to clipboard
open suspend override fun delete(path: Path)

Deletes a file or directory denoted by the path. If the item is a directory, it will be deleted recursively with all its contents. The operation is performed with Dispatchers.IO context.

Link copied to clipboard
open suspend override fun exists(path: Path): Boolean

Checks if a path exists in the filesystem.

Link copied to clipboard
open override fun extension(path: Path): String

Gets the extension of a path. This method works with the path structure and doesn't check if the path actually exists in the filesystem.

Link copied to clipboard

Filters the current read-only file system implementation such that only paths that are accepted by filter are visible and accessible.

Filters the current read-write file system implementation such that only paths that are accepted by filter are visible and accessible.

Link copied to clipboard
open override fun fromAbsolutePathString(path: String): Path

Creates a Path object from an absolute path string. This method works with the path structure and doesn't check if the path actually exists in the filesystem.

Link copied to clipboard
open suspend override fun getFileContentType(path: Path): FileMetadata.FileContentType

Detects the type of content stored in a file using a path.

Link copied to clipboard
open suspend override fun inputStream(path: Path): Source

Creates a Source for reading from a file at the specified path. The returned Source is buffered.

Link copied to clipboard
open override fun joinPath(base: Path, vararg parts: String): Path

Resolves strings from parts against a base path. This method works with the path structure and doesn't check if the path actually exists in the filesystem.

Link copied to clipboard
open suspend override fun list(directory: Path): List<Path>

Lists contents of a directory. Children are sorted by name. The listing is not recursive.

Link copied to clipboard
open suspend override fun metadata(path: Path): FileMetadata?

Retrieves metadata for a file or directory using a path.

Link copied to clipboard
open suspend override fun move(source: Path, target: Path)

Moves a file or directory from source to target. If the source is a directory, all its contents are moved recursively. Parent directories of the target will be created if they don't exist. The operation is performed with Dispatchers.IO context.

Link copied to clipboard
open override fun name(path: Path): String

Gets the name component of a path. This method works with the path structure and doesn't check if the path actually exists in the filesystem.

Link copied to clipboard
open suspend override fun outputStream(path: Path, append: Boolean): Sink

Creates a Sink for writing to a file. If the file doesn't exist, it will be created. If the parent directories don't exist, they will be created. The returned Sink is buffered. It is created with Dispatchers.IO context.

Link copied to clipboard
open override fun parent(path: Path): Path?

Gets the parent path of a given path. This method works with the path structure and doesn't check if the path actually exists in the filesystem.

Link copied to clipboard
open suspend override fun readBytes(path: Path): ByteArray

Reads the content of a file at the specified path.

Link copied to clipboard

Reads the entire content of a file as a string.

Link copied to clipboard
open override fun relativize(root: Path, path: Path): String?

Computes the relative path from a root to a target path. It doesn't check if the paths actually exist in the filesystem.

Link copied to clipboard
open suspend override fun size(path: Path): Long

Gets the size of a file in bytes.

Link copied to clipboard
open override fun toAbsolutePathString(path: Path): String

Converts a path to its absolute path string representation. This method works with the path structure and doesn't check if the path actually exists in the filesystem.

Link copied to clipboard
open suspend override fun writeBytes(path: Path, data: ByteArray)

Writes content to a file. If the file doesn't exist, it will be created. If the file exists, its content will be overwritten. Parent directories will be created if they don't exist. The operation is performed with Dispatchers.IO context.

Link copied to clipboard
suspend fun <Path> FileSystemProvider.ReadWrite<Path>.writeText(path: Path, content: String)

Writes a string to a file, replacing any existing content.