os/temp
Making a temporary file or directory under a unique name.
import os.temp
On this page
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(): strMakes an empty file under a unique name in the system temporary directory and returns its path.
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)
endOutputtrue
false
true
false
Directory
func Directory(): strMakes 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): intRemoves a temporary file.
The example for this item is shown with the ones above: os-temp-File.salam
RemoveDir
func RemoveDir(p: str): intRemoves a temporary directory with everything in it.
The example for this item is shown with the ones above: os-temp-File.salam