Reference

std/fs/metadata

std/fs/src/metadata.trb

What File.metadata answers about a path: Metadata, with its FileKind and its Permissions.

type FileKind

type FileKind with Show, Equals, Hash

What a path names.

case File

case File

A regular file: bytes with a length.

case Directory

case Directory

Not documented.

case Other

case Other

A device, a pipe, a socket: something that is none of the three.

type Permissions

type Permissions with Show, Equals, Hash

The permission bits of a file, the way POSIX writes them: read, write and execute for the owner, the group and everybody else - 0b111_101_101, which is 0o755 - plus the set-id and sticky bits above them.

Windows has one bit of its own, read-only, and the bits are made up from it the way its C library does: everybody may read, everybody may write unless the file is read-only, and a directory or a program (.exe, .com, .bat, .cmd) may be executed. Setting them there sets read-only where the owner's write bit is clear, and nothing else.

Examples

const permissions = Permissions 0b110_100_000
print permissions
print permissions.writable()
// prints rw-r-----
// prints true

field mode

mode: Int

The bits, 0b111_111_111_111 at most.

fn readable

fn readable(): Bool

Whether the owner may read it.

fn writable

fn writable(): Bool

Whether the owner may write it: on Windows, whether it is not read-only.

fn executable

fn executable(): Bool

Whether the owner may execute it - a directory: enter it.

fn withWritable

fn withWritable(writable: Bool): Self

The same permissions with the owner's write bit set, or cleared where writable is false.

fn show

fn show(): String

The nine letters ls -l shows: rwxr-xr-x.

type Metadata

type Metadata with Show, Equals

What a path is, how large, when it was last written, and who may do what with it.

Examples

use File from "std/fs"

fn describe(path: String): String {
  match File.metadata(path) {
    Ok(found) => "{found.kind}, {found.size} bytes, written {found.modified}"
    Fail(problem) => problem.show()
  }
}

field kind

kind: FileKind

Not documented.

field size

size: Int

In bytes. Nothing a program can rely on for a directory (0 on Windows, a block's size elsewhere).

field modified

modified: Timestamp

When its content was last written.

field permissions

permissions: Permissions

Not documented.

fn isFile

fn isFile(): Bool

Whether it is a regular file.

fn isDirectory

fn isDirectory(): Bool

Whether it is a directory.