Skip to content

File List API

The File List API provides functionality to manage and interact with files and folders in the Acode workspace. It returns a tree structure representing the file system hierarchy.

Usage

Basic Usage

js
// Get the fileList API
const fileList = acode.require('fileList');

// Get list of all files
const files = await fileList();

// Process files
files.forEach(file => {
		console.log(`Name: ${file.name}`);
		console.log(`Path: ${file.path}`);
});

Event Handling

js
const fileList = acode.require('fileList');

// Listen for file changes
fileList.on('add-file', (file) => {
		console.log(`New file added: ${file.path}`);
});

fileList.on('remove-file', (file) => {
		console.log(`File removed: ${file.path}`);
});

Tree Object

The Tree object represents files and folders in the workspace.

Properties

PropertyTypeDescription
namestringName of the file/folder
urlstringAbsolute URL path
pathstringRelative path
childrenArray<Tree>Child files/folders (if directory)
parentTreeParent folder reference
isConnectedbooleanWhether root is in open folder list
rootTreeRoot folder reference

Methods

update(url: string, name?: string)

Updates the file/folder URL and name

js
tree.update('/new/path/file.txt', 'newname.txt');

toJSON()

Converts tree to JSON representation

js
const json = tree.toJSON();

static fromJSON(json: object)

Creates tree from JSON data

js
const tree = Tree.fromJSON(jsonData);

static create(url: string, name?: string, isDirectory?: boolean)

Creates a new tree instance

js
const newTree = await Tree.create('/path/file.txt', 'file.txt');

Events

The File List API emits the following events:

EventDescription
add-fileFile added to workspace
remove-fileFile removed from workspace
add-folderFolder added to workspace
remove-folderFolder removed from workspace
refreshFile list refreshed

Error Handling

The API includes built-in error handling with automatic retries for failed operations. Use try/catch blocks when calling async methods:

js
try {
		const files = await fileList();
} catch (err) {
		console.error('Error accessing files:', err);
}

Released under the MIT License.