Skip to main content

LensStudio:FileSystem.Watcher

Class

Watches a file or directory for changes and emits events when modifications occur.

Index

Example

// Watcher monitors a filesystem path for additions, modifications, moves,
// and removals. Create one via the static Watcher.create(path) method,
// connect to its signals, then call start() to begin watching.

const { Watcher } = await import('LensStudio:FileSystem');
const model = this.pluginSystem.findInterface(Editor.Model.IModel) as Editor.Model.IModel;
const assetsDir = model.project.assetsDirectory;

// Create a watcher on the project's assets directory
const watcher = Watcher.create(assetsDir);
console.log('Watcher created for path:', assetsDir.toString());

// Connect to file-change signals
this.connections.push(
watcher.onAdded.connect((path: Editor.Path) => {
console.log('File added:', path.toString());
})
);
this.connections.push(
watcher.onModified.connect((path: Editor.Path) => {
console.log('File modified:', path.toString());
})
);
this.connections.push(
watcher.onRemoved.connect((path: Editor.Path) => {
console.log('File removed:', path.toString());
})
);
this.connections.push(
watcher.onMoved.connect((oldPath: Editor.Path, newPath: Editor.Path) => {
console.log('File moved from', oldPath.toString(), 'to', newPath.toString());
})
);

// Start watching
watcher.start();
console.log('Watcher is active:', watcher.isWatching);
console.log('Watcher path:', watcher.path.toString());

Extends

Properties

isWatching

readonly isWatching: boolean

Indicates whether the watcher is currently active.


onAdded

readonly onAdded: signal1<Path, void>

Signal emitted when a file is added at the watched path.


onModified

readonly onModified: signal1<Path, void>

Signal emitted when a file is modified at the watched path.


onMoved

readonly onMoved: signal2<Path, Path, void>

Signal emitted when a file is moved at the watched path.


onRemoved

readonly onRemoved: signal1<Path, void>

Signal emitted when a file is removed from the watched path.


path

readonly path: Path

The filesystem path being monitored by this watcher.

Methods

create()

static create(path): Watcher

Creates a new Watcher instance for the specified path.

Parameters

ParameterType
pathPath

Returns

Watcher


getTypeName()

static getTypeName(): string

Returns the type name of this class.

Returns

string

Overrides

ScriptObject.getTypeName


getTypeName()

getTypeName(): string

Returns the name of this object's type.

Returns

string

Inherited from

ScriptObject.getTypeName


isOfType()

isOfType(type): boolean

Returns true if the object is of the specified type.

Parameters

ParameterType
typestring

Returns

boolean

Inherited from

ScriptObject.isOfType


isSame()

isSame(other): boolean

Returns true if this object refers to the same instance as the given object.

Parameters

ParameterType
otherScriptObject

Returns

boolean

Inherited from

ScriptObject.isSame


start()

start(): void

Begins watching the configured path for filesystem events.

Returns

void


stop()

stop(): void

Stops watching the configured path for filesystem events.

Returns

void