Functions for working with files and directories are described here.



The finfo is used for getting information about a file and has the following fields:

  • str Name - base name of the file

  • int Size - length in bytes for regular files

  • int Mode - file's mode and permission bits.

  • time Time - last modification time

  • bool IsDir - true if it is a directory


AppendFile(str filename, buf|str data)

The AppendFile function appends data of buf variable or a string to a file named by filename. If the file does not exist, AppendFile creates it with 0644 permissions.

ChDir(str dirname)

The ChDir function changes the current directory.

CopyFile(str src, str dest) int

The CopyFile function copies src file to dest file. If dest file exists it is overwritten. The function returns the number of copied bytes.

CreateDir(str dirname)

The CreateDir function creates a directory named dirname, along with any necessary parents. If dirname is already a directory, CreateDir does nothing.

FileInfo(str name) finfo

The FileInfo function gets information about the named file and returns finfo structure.

GetCurDir() str

The GetCurDir function returns the current directory.

Md5File(str filename) str

The Md5File function returns the MD5 hash of the specified file as a hex string.

ReadDir(str dirname) arr.finfo

The ReadDir function reads the directory named by dirname and returns a list of directories and files entries.

ReadFile(str filename) str

The ReadFile function reads the specified file and returns the contents as a string.

ReadFile(str filename, buf out) buf

The ReadFile function reads the file named by filename to the buf variable out and returns it.

ReadFile(str filename, int offset, int length) buf

The ReadFile function reads data from the filename file starting at offset offset and length length. If offset is less than zero, then the offset is counted from the end to the beginning of the file.

Remove(str name)

The Remove function removes a file or an empty directory.

RemoveDir(str dirname)

The RemoveDir function removes dirname directory and any children it contains.

Rename(str oldpath, str newpath)

The Rename function renames (moves) oldpath to newpath. If newpath already exists and is not a directory, Rename replaces it.

SetFileTime(str name, time modtime)

The SetFileTime function changes the modification time of the named file.

Sha256File(str filename) str

The Sha256File function returns the SHA256 hash of the specified file as a hex string.

TempDir() str

The TempDir function returns the default temporary directory.

TempDir(str path, str prefix) str

The TempDir function creates a new temporary directory in the directory path with a name beginning with prefix and returns the path of the new directory. If path is the empty string, TempDir uses the default temporary directory.

WriteFile(str filename, buf|str data)

The WriteFile function writes data of buf variable or a string to a file named by filename. If the file does not exist, WriteFile creates it with 0777 permissions, otherwise the file is truncated before writing.