Search results

There are no results.

std.fs.Metadata

class pub Metadata

A type containing metadata of a file or directory, such as its type and creation time.

Fields

type

let pub @type: FileType

The type of the file.

size

let pub @size: Int

The size of the file in bytes.

Instance methods

accessed_at

Show source code
Hide source code
fn pub accessed_at -> DateTime {
  @accessed_at.to_date_time
}
fn pub accessed_at -> DateTime

Returns the time at which the file was last accessed.

This corresponds to the atime field of stat() on Unix systems.

created_at

Show source code
Hide source code
fn pub created_at -> Option[DateTime] {
  match @created_at {
    case Some(v) -> Option.Some(v.to_date_time)
    case _ -> Option.None
  }
}
fn pub created_at -> Option[DateTime]

Returns the time at which the file was created.

This corresponds to the btime field of statx() on Linux, and the birthtime field on other Unix platforms.

Support for creationg times is a bit inconsistent: FreeBSD and macOS have supported it for a long time, but Linux only supports it since 4.11. Even then, depending on the file system the creation time might not be available (e.g. /proc/stat on Linux doesn't have one), or the system call might not be available for other reasons (e.g. it's blocked).

Rather than dealing with this by returning a nonsensical value (e.g. 1970-01-01 00:00:00), an Option[DateTime] is returned. If the creation time is available, the value is a Option.Some(DateTime), otherwise it's a None.

modified_at

Show source code
Hide source code
fn pub modified_at -> DateTime {
  @modified_at.to_date_time
}
fn pub modified_at -> DateTime

Returns the time at which the file was last modified.

This corresponds to the "mtime" field of stat() on Unix systems.