TempDirectory

Interface representing a temporary directory.

This object provides the path to the created directory along with an open file descriptor or file handle. It automatically deletes the directory when close is called.

Use createTempDirectory to create temporary directory from common code. Additional factories for platform-specific implementations are available on target platforms, offering more flexible customization and usage capabilities.

The absolutePath method returns the absolute path of the temporary directory.

This object implements AutoCloseable, call close when the directory is no longer needed. The directory is automatically recursively deleted when close is called. Set TempDirectory.deleteOnClose to false to preserve the directory; however, close must still be called.

The open file descriptor or directory handle is available through the TempDirectory.root property. It can be used with platform-specific filesystem functions (for example, openat2() on Linux).

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard
abstract var deleteOnClose: Boolean

Specifies whether the temporary directory should be deleted when close is called.

Link copied to clipboard
abstract val root: FH

Depending on the implementation, the absolute path to the created directory, the native open file descriptor, or a native file handle. Do not close the provided file descriptor yourself, as it will lead to incorrect behavior.

Functions

Link copied to clipboard

Returns the absolute path of the temporary directory.

Link copied to clipboard
abstract fun append(name: String): TempDirectoryPath

Appends name to the absolutePath using the platform-specific file system separator and returns the complete path for name within the temporary directory.

Link copied to clipboard
abstract override fun close()

Closes the temporary directory.

Link copied to clipboard
abstract fun delete()

Recursively deletes the temporary directory.