API. FILESYSTEM

The API.FILESYSTEM class provides a set of interfaces for managing the file system on the controller. It includes methods for retrieving file and directory contents, creating, updating, and deleting files or directories, and checking file existence. This class simplifies file system operations, enabling developers to efficiently interact with and manage files on the controller.

Methods

copy(source, destination, overwrite)

Recursively copies a file or directory (including all subdirectories and files).

Parameters:
NameTypeDescription
sourcestring

Source path

destinationstring

Destination path

overwriteboolean

Overwrites the directory or file if it already exists in the destination path.

Example
await API.FILESYSTEM.copy("$HOME/EIO.cfg","$HOME/WebApps/EIO.cfg")

createDirectory(directoryPath)

Creates a new directory.

Parameters:
NameTypeDescription
directoryPathstring

The directory path

Example
await API.FILESYSTEM.createDirectory("$HOME/testFolder")

createNewFile(directoryPath, fileName, data, overwrite)

Create a new file

Parameters:
NameTypeDescription
directoryPathstring

directory path

fileNamestring

file name

datastring

data content

overwriteboolean

Overwrite if the file already exists

Example
await API.FILESYSTEM.createNewFile("$HOME", "test.txt", "test new", true)

deleteDirectory(directoryPath)

Delete directory

Parameters:
NameTypeDescription
directoryPathstring

directory path

Example
await API.FILESYSTEM.deleteDirectory("$HOME/testFolder")

deleteDirectoryContent(directoryPath)

Delete all directories and files in a directory

Parameters:
NameTypeDescription
directoryPathstring

directory path

Example
await API.FILESYSTEM.deleteDirectoryContent("$HOME/testFolder")

deleteFile(directoryPath, fileName)

Delete file

Parameters:
NameTypeDescription
directoryPathstring

directory path

fileNamestring

file name

Example
await API.FILESYSTEM.deleteFile("$HOME", "test.txt")

fileExists(directoryPath, fileName) → {Promise.<boolean>}

Detect if the file already exists

Parameters:
NameTypeDescription
directoryPathstring

directory path

fileNamestring

file name

Returns:
  • true if the file exists, false otherwise
Type: 
Promise.<boolean>
Example
const fileExists = await API.FILESYSTEM.fileExists("$HOME", "test.txt")

getDirectoryContents(path)

Gets the content of a directory with specified path

Parameters:
NameTypeDescription
pathstring

Path to the file, including file name

Example
// Get the content of the TEMP directory of controller
await API.FILESYSTEM.getDirectoryContents("$TEMP")

getFile(path, file)

Get the content of a file with specified path

Parameters:
NameTypeDescription
pathstring

Path to the file, optional - including file name

filestring

Name of the file

Example
// Get the file content of the file EIO.cfg in Home directory
await API.FILESYSTEM.getFile("$HOME","EIO.cfg")

getFiles(path) → {Promise.<Array.<object>>}

Get a list of files objects including name and content

Parameters:
NameTypeDescription
pathstring

Path to the file, including file name

Returns:
  • Array of file objects [ {name, content}]
Type: 
Promise.<Array.<object>>
Example
await API.FILESYSTEM.getFiles("$HOME")

updateFile(directoryPath, fileName, data) → {Promise.<Array.<object>>}

Update the file content

Parameters:
NameTypeDescription
directoryPathstring

directory path

fileNamestring

fileName

datastring

content to be updated

Returns:
  • Array of file objects [ {name, content}]
Type: 
Promise.<Array.<object>>
Example
await API.FILESYSTEM.updateFile("$HOME","test.txt","testcontent")