LensStudio:FileSystem.Watcher
ClassWatches a file or directory for changes and emits events when modifications occur.
Index
Properties
Methods
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
readonlyisWatching:boolean
Indicates whether the watcher is currently active.
onAdded
Signal emitted when a file is added at the watched path.
onModified
Signal emitted when a file is modified at the watched path.
onMoved
Signal emitted when a file is moved at the watched path.
onRemoved
Signal emitted when a file is removed from the watched path.
path
readonlypath:Path
The filesystem path being monitored by this watcher.
Methods
create()
staticcreate(path):Watcher
Creates a new Watcher instance for the specified path.
Parameters
| Parameter | Type |
|---|---|
path | Path |
Returns
Watcher
getTypeName()
staticgetTypeName():string
Returns the type name of this class.
Returns
string
Overrides
getTypeName()
getTypeName():
string
Returns the name of this object's type.
Returns
string
Inherited from
isOfType()
isOfType(
type):boolean
Returns true if the object is of the specified type.
Parameters
| Parameter | Type |
|---|---|
type | string |
Returns
boolean
Inherited from
isSame()
isSame(
other):boolean
Returns true if this object refers to the same instance as the given object.
Parameters
| Parameter | Type |
|---|---|
other | ScriptObject |
Returns
boolean
Inherited from
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