ballerina/file module
Module overview
This module contains services that register listeners against a local folder and identify events that create, modify, and delete files.
Samples
The sample given below shows how a Listener
is used to listen to the local folder. The onCreate()
resource method gets invoked when a file is created inside the target/fs
folder. Use the onDelete()
and onModify()
methods to listen to the delete and modify events.
import ballerina/file;
listener file:Listener localFolder = new ({
path: "target/fs",
recursive: false
});
service fileSystem on localFolder {
resource function onCreate(file:FileEvent m) {
}
}
Records Summary
Record | Description | ||
---|---|---|---|
FileEvent | Represents an event which will trigger when there is a changes to listining direcotry. | ||
ListenerConfig | Represents configurations that required for directory listener. |
Objects Summary
Object | Description | ||
---|---|---|---|
Listener | Represents directory listener endpoint where used to listen to a directory in the local file system. |
public type FileEvent record
Represents an event which will trigger when there is a changes to listining direcotry.
Field Name | Data Type | Default Value | Description |
---|---|---|---|
name | string | Absolute file URI for triggerd event |
|
operation | string | Triggered event action. This can be create, delete or modify |
public type ListenerConfig record
Represents configurations that required for directory listener.
Field Name | Data Type | Default Value | Description |
---|---|---|---|
path | string? | () | Directory path which need to listen |
recursive | boolean | false | Recursively monitor all sub folders or not in the given direcotry path |
public type Listener object
Represents directory listener endpoint where used to listen to a directory in the local file system.
-
<Listener> __init(file:ListenerConfig listenerConfig)
Parameter Name Data Type Default Value Description listenerConfig file:ListenerConfig -
<Listener> __start() returns (error?<>)
Return Type Description error?<> -
<Listener> __stop() returns (error?<>)
Return Type Description error?<> -
<Listener> __attach(service s, string? name) returns (error?<>)
Parameter Name Data Type Default Value Description s service name string? () Return Type Description error?<>