Standard library · System and tools

os/temp

Making a temporary file or directory under a unique name.

import os.temp
On this page
  1. Functions

For data that is only needed while the program runs, make a temporary file or directory. The names are unique, so several copies of the program running at once do not collide. Removing them is up to you.

Functions

File

func File(): str
Makes an empty file under a unique name in the system temporary directory and returns its path.
os-temp-File.salam
import os
import os.temp

func main:
    p := temp.File()
    println os.Exists(p)
    temp.Remove(p)
    println os.Exists(p)
    d := temp.Directory()
    println os.IsDir(d)
    temp.RemoveDir(d)
    println os.Exists(d)
end
Outputtrue false true false

Directory

func Directory(): str
Makes an empty directory under a unique name and returns its path.

The example for this item is shown with the ones above: os-temp-File.salam

Remove

func Remove(p: str): int
Removes a temporary file.

The example for this item is shown with the ones above: os-temp-File.salam

RemoveDir

func RemoveDir(p: str): int
Removes a temporary directory with everything in it.

The example for this item is shown with the ones above: os-temp-File.salam