Standard library · System and tools

fs.file

Deprecated: every function forwards to fs. Write import fs instead of import fs.file.

import fs.file

The fs.file package is deprecated. Everything in it now lives in fs, and each function here only calls its fs twin, so old programs keep compiling and behave the same. In new code write import fs and call fs.ReadText(path), fs.WriteText(path, text), fs.Copy(src, dst) and the rest straight from fs. file.FileInfo is the same type as fs.FileInfo, so values pass between the two without conversion.

To migrate, change import fs.file to import fs and replace each file. prefix with fs.. The names, arguments and results are exactly the same. See the fs page for the guides and the full description of each function.

Move old code to fs

Change import fs.file to import fs and the file. prefix of every call to fs.. Nothing else changes: file.ReadText(p) becomes fs.ReadText(p), file.Stat(p) becomes fs.Stat(p), and a variable declared as file.FileInfo may be passed wherever fs.FileInfo is expected.

Using both in one program

A program may import fs and fs.file together while it is being migrated. Both prefixes call the same code, so the results are identical, and the compiler does not treat the two FileInfo names as different types.

Types

FileInfo

type FileInfo = fs.FileInfo
Everything about a file.
fs-file-Migrate.salam
import fs
import fs.file

func main:
    file.WriteText("legacy.txt", "old code")
    println file.ReadText("legacy.txt"), fs.ReadText("legacy.txt")
    println file.Size("legacy.txt") == fs.Size("legacy.txt"), file.Exists("legacy.txt")
    info := file.Stat("legacy.txt")
    println info.exists, info.size
    file.Delete("legacy.txt")
    println fs.Exists("legacy.txt")
end
Outputold code old code true true true 8 false

Functions

Open

func Open(path: str, mode: str): File*
Deprecated: the same as fs.Open.

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

Close

func Close(f: File*)
Deprecated: the same as fs.Close.

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

ReadText

func ReadText(path: str): str
Deprecated: the same as fs.ReadText.

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

ReadAll

func ReadAll(path: str): str
Deprecated: the same as fs.ReadAll.

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

ReadBytes

func ReadBytes(path: str, n: int): str
Deprecated: the same as fs.ReadBytes.

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

ReadLines

func ReadLines(path: str): Vector<str>
Deprecated: the same as fs.ReadLines.

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

WriteText

func WriteText(path: str, data: str): int
Deprecated: the same as fs.WriteText.

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

WriteBytes

func WriteBytes(path: str, data: str): int
Deprecated: the same as fs.WriteBytes.

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

Append

func Append(path: str, data: str): int
Deprecated: the same as fs.Append.

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

AtomicWrite

func AtomicWrite(path: str, data: str): int
Deprecated: the same as fs.AtomicWrite.

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

Size

func Size(p: str): i64
Deprecated: the same as fs.Size.

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

ModTime

func ModTime(p: str): i64
Deprecated: the same as fs.ModTime.

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

AccessedTime

func AccessedTime(p: str): i64
Deprecated: the same as fs.AccessedTime.

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

CreatedTime

func CreatedTime(p: str): i64
Deprecated: the same as fs.CreatedTime.

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

Permissions

func Permissions(p: str): int
Deprecated: the same as fs.Permissions.

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

Chmod

func Chmod(p: str, mode: int): int
Deprecated: the same as fs.Chmod.

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

Extension

func Extension(p: str): str
Deprecated: the same as fs.Extension.

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

MimeType

func MimeType(p: str): str
Deprecated: the same as fs.MimeType.

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

Stat

func Stat(p: str): FileInfo
Deprecated: the same as fs.Stat.

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

Copy

func Copy(src: str, dst: str): int
Deprecated: the same as fs.Copy.

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

Move

func Move(src: str, dst: str): int
Deprecated: the same as fs.Move.

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

Rename

func Rename(src: str, dst: str): int
Deprecated: the same as fs.Rename.

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

Delete

func Delete(p: str): int
Deprecated: the same as fs.Delete.

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

Exists

func Exists(p: str): bool
Deprecated: the same as fs.Exists.

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

Md5Hex

func Md5Hex(p: str): str
Deprecated: the same as fs.Md5Hex.

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

Sha1Hex

func Sha1Hex(p: str): str
Deprecated: the same as fs.Sha1Hex.

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

Sha256Hex

func Sha256Hex(p: str): str
Deprecated: the same as fs.Sha256Hex.

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

Sha512Hex

func Sha512Hex(p: str): str
Deprecated: the same as fs.Sha512Hex.

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