FileMetadata

class FileMetadata(val isRegularFile: Boolean = false, val isDirectory: Boolean = false, val symlinkTarget: Path? = null, val size: Long? = null, val createdAtMillis: Long? = null, val lastModifiedAtMillis: Long? = null, val lastAccessedAtMillis: Long? = null, extras: Map<KClass<*>, Any> = mapOf())

Description of a file or another object referenced by a path.

In simple use a file system is a mechanism for organizing files and directories on a local storage device. In practice file systems are more capable and their contents more varied. For example, a path may refer to:

  • An operating system process that consumes data, produces data, or both. For example, reading from the /dev/urandom file on Linux returns a unique sequence of pseudorandom bytes to each reader.

  • A stream that connects a pair of programs together. A pipe is a special file that a producing program writes to and a consuming program reads from. Both programs operate concurrently. The size of a pipe is not well defined: the writer can write as much data as the reader is able to read.

  • A file on a remote file system. The performance and availability of remote files may be quite different from that of local files!

  • A symbolic link (symlink) to another path. When attempting to access this path the file system will follow the link and return data from the target path.

  • The same content as another path without a symlink. On UNIX file systems an inode is an anonymous handle to a file's content, and multiple paths may target the same inode without any other relationship to one another. A consequence of this design is that a directory with three 1 GiB files may only need 1 GiB on the storage device.

This class does not attempt to model these rich file system features! It exposes a limited view useful for programs with only basic file system needs. Be cautious of the potential consequences of special files when writing programs that operate on a file system.

File metadata is subject to change, and code that operates on file systems should defend against changes to the file that occur between reading metadata and subsequent operations.

Constructors

Link copied to clipboard
constructor(isRegularFile: Boolean = false, isDirectory: Boolean = false, symlinkTarget: Path? = null, size: Long? = null, createdAtMillis: Long? = null, lastModifiedAtMillis: Long? = null, lastAccessedAtMillis: Long? = null, extras: Map<KClass<*>, Any> = mapOf())

Properties

Link copied to clipboard
val createdAtMillis: Long? = null

The system time of the host computer when this file was created, if the host file system supports this feature. This is typically available on Windows NTFS file systems and not available on UNIX or Windows FAT file systems.

Link copied to clipboard
val extras: Map<KClass<*>, Any>

Additional file system-specific metadata organized by the class of that metadata. File systems may use this to include information like permissions, content-type, or linked applications.

Link copied to clipboard
val isDirectory: Boolean = false

True if the path refers to a directory that contains 0 or more child paths.

Link copied to clipboard
val isRegularFile: Boolean = false

True if this file is a container of bytes. If this is true, then size is non-null.

Link copied to clipboard

The system time of the host computer when this file was most recently read or written.

Link copied to clipboard

The system time of the host computer when this file was most recently written.

Link copied to clipboard
val size: Long? = null

The number of bytes readable from this file. The amount of storage resources consumed by this file may be larger (due to block size overhead, redundant copies for RAID, etc.), or smaller (due to file system compression, shared inodes, etc).

Link copied to clipboard
val symlinkTarget: Path? = null

The absolute or relative path that this file is a symlink to, or null if this is not a symlink. If this is a relative path, it is relative to the source file's parent directory.

Functions

Link copied to clipboard
fun copy(isRegularFile: Boolean = this.isRegularFile, isDirectory: Boolean = this.isDirectory, symlinkTarget: Path? = this.symlinkTarget, size: Long? = this.size, createdAtMillis: Long? = this.createdAtMillis, lastModifiedAtMillis: Long? = this.lastModifiedAtMillis, lastAccessedAtMillis: Long? = this.lastAccessedAtMillis, extras: Map<KClass<*>, Any> = this.extras): FileMetadata
Link copied to clipboard
fun <T : Any> extra(type: KClass<out T>): T?

Returns extra metadata of type type, or null if no such metadata is held.

Link copied to clipboard
open override fun toString(): String