Skip to main content

Filesystem

API for filesystem-related functions.

Functions

Filesystem.toAbsolutePath

Converts a relative path to an absolute path.

Filesystem.toAbsolutePath(path: string, base?: string): string

Parameters

NameTypeDefault ValueDescription
pathstringRequiredThe path to convert.
basestring?nilThe base path to use.

Returns

NameTypeDescription
absolutePathstringThe absolute path.

Filesystem.readFile

Reads a file.

Filesystem.readFile(relativePath: string): buffer

Parameters

NameTypeDefault ValueDescription
relativePathstringRequiredThe relative path to the file.

Returns

NameTypeDescription
contentsbufferThe contents of the file.

Filesystem.fileExists

Checks if a file exists.

Filesystem.fileExists(path: string): boolean

Parameters

NameTypeDefault ValueDescription
pathstringRequiredThe path to the file relative to the script directory.

Returns

NameTypeDescription
existsbooleanTrue if the file exists, false otherwise.

Filesystem.list

Returns the files and folders present in the given directory.

Filesystem.list(path: string): DirectoryContents

Parameters

NameTypeDefault ValueDescription
pathstringRequiredPath to the directory to list relative to the script directory.

Returns

NameTypeDescription
contentsDirectoryContentsNo description

Types

DirectoryContents

List of file and subfolder names in a directory

type DirectoryContents = { directories: string[], files: string[] }

Properties

FieldTypeDescription
directoriesstring[]No description
filesstring[]No description