Standard library · System and tools

fs

File times and permissions; the base of the file, dir and path packages.

import fs
On this page
  1. Functions

The fs package holds a few shared functions and three sub-packages you will use far more often: fs.file, fs.dir and fs.path. Times are in seconds since the start of 1970, Unix time.

Write permissions in octal, such as 0o644, meaning the owner reads and writes and everyone else reads. Permissions returns the same digits as an ordinary number, such as 644, so that it reads easily.

Functions

ModTime

func ModTime(path: str): i64
When the file's content was last changed.
fs-ModTime.salam
import fs
import fs.file

func main:
    file.WriteText("report.txt", "hello")
    t := fs.ModTime("report.txt")
    println t > 0, fs.AccessedTime("report.txt") > 0, fs.CreatedTime("report.txt") >= 0
    fs.Chmod("report.txt", 0o644)
    println fs.Permissions("report.txt")
end
Outputtrue true true 644

AccessedTime

func AccessedTime(path: str): i64
When the file was last read.

The example for this item is shown with the ones above: fs-ModTime.salam

CreatedTime

func CreatedTime(path: str): i64
When the file was created, or zero where the system does not keep it.

The example for this item is shown with the ones above: fs-ModTime.salam

Chmod

func Chmod(path: str, mode: int): int
Changes a file's permissions; give them in octal, such as 0o644.

The example for this item is shown with the ones above: fs-ModTime.salam

Permissions

func Permissions(path: str): int
A file's permissions, as octal digits, such as 644.

The example for this item is shown with the ones above: fs-ModTime.salam