Build a File-Driven Integration
onModify handler to track file changes and uses printInfo to log file modification events.File integrations are ideal for batch uploads, scheduled file processing, and ETL workflows triggered by files appearing in a folder or FTP server.
Prerequisites
A working WSO2 Integrator environment.
Local setupInstall and launch WSO2 Integrator on your machine.
WSO2 Cloud AccountFor AI assisted development and WSO2 Cloud deployments.
Also required, a file at the listener path to watch. Create one if you don't have one:
- macOS / Linux
- Windows
echo "test" > /tmp/testfile.txt
mkdir C:\tmp 2>nul
echo test > C:\tmp\testfile.txt
Step 1: Create the integration
If you're using the cloud editor, a project is already open, so you can skip this step and go directly to Step 2: Add a file integration artifact.
-
Open WSO2 Integrator.
-
Click Create in the Create a Project card.

-
Set Project Name to
file-integration. -
Set Integration Name to
FileTracker. -
Click Create.

Step 2: Add a file integration artifact
-
Select your integration from the project overview canvas.
-
In the design view, click Add Artifact Manually.

-
Select Local Files under File Integration.

-
Set Path to the folder you want to watch:
- macOS / Linux
- Windows
/tmpC:\tmp -
Click Create.

Step 3: Add onModify event handler
-
In the service designer view, click + Add Handler.
-
Select onModify.

-
In the Configure onModify Handler panel, clear both On Success and On Error under File Handling Options, then click Save. Both options arrive ticked and set to Move, which moves each processed file out of the watched directory. Clearing them keeps
testfile.txtin/tmp, where the later steps expect it. For details, see Post-processing: moving or deleting files.
Step 4: Add file tracking logic
-
Click + in the flow diagram.
-
Search for
printInfoand select printInfo.
-
Set Msg to
File modified. -
Click Save.

Step 5: Run and test
-
Click Run in the toolbar.
-
Run the modify command in your terminal to trigger the handler:
- macOS / Linux
- Windows
echo "modify" > /tmp/testfile.txt
echo modify > C:\tmp\testfile.txt
-
Confirm the run terminal shows the log line
File modified.
Source code
View the generated Ballerina code
The steps above generate the following complete, runnable Ballerina program:
Change the listener path from "/tmp" to "C:\\tmp" (backslash escaped) before running the program.
import ballerina/file;
import ballerina/log;
listener file:Listener fileListener = new (path = "/tmp", recursive = false);
service file:Service on fileListener {
remote function onModify(file:FileEvent event) returns error? {
do {
log:printInfo("File modified");
} on fail error err {
// handle error
return error("unhandled error", err);
}
}
}
What's next
- Local files — Full Local Files listener reference (events, recursive watching, file handlers)
- FTP/SFTP — Watch and process files on remote FTP or SFTP servers
- Streaming large files — Process large files without loading them fully into memory
- CSV fault tolerance — Handle errors and partial failures when processing CSV files