Skip to main content

File System APIs

The File System APIs (api.fs) provide access to a set of methods with permissions such as read, write, and delete files/directories.

Note

The host application creates a root directory for each plugin. Therefore, each API method operates on a relative path.

readDir

Reads the list of files from a directory.

Method

readDir(dirPath: string): Promise<string[]>

Parameters

Name

Type

Description

dirPath

string

Relative path to directory

Returns

Promise<string[]> Resolves with a list of file names contained in the directory

Throws

Throws error if the path format is invalid.

readFile

Reads file content from provided relative path.

Method

readFile(path: string): Promise<string>

Parameters

Name

Type

Description

path

string

Relative path to file

Returns

Promise<string> Resolves with the file content

Throws

Throws error if the path format is invalid.

unlink

Removes a file from the file system.

Method

unlink(path: string): Promise<void>

Parameters

Name

Type

Description

path

string

Relative path to a file

Returns

Promise<void> Resolves upon removal of file

Throws

Throws error if the path format is invalid.

writeFile

Writes content to a file. Creates a new file if one does not already exist. May either append to an existing file or overwrite with new content.

Method

writeFile(path: string, content: string, append?: boolean): Promise<void>

Parameters

Name

Type

Description

path

string

Relative path to a file

content

string

Content to write to a file

append

boolean

(Optional) true - append content to file; false - overwrite existing file with new content. Default: false.

Returns

Promise<void> Resolves upon file save

Throws

Throws error if for an invalid path format