This API documentation is for Ballerina 1.2.0. View API documentation for the latest release.

Module : file

Module Overview

This module contains functions to perform file system based operations such as create, delete, rename the file/directory, and retrieve metadata of the file.

For an example on the usage of the operations, see the File Example.

Directory Listener

The Directory Listener is used to listen to a directory in the local file system. It notifies when new files are created in the directory or when the existing files are deleted or modified.

For an example on the usage of the operations, see the Directory Listener Example.

Records

Detail

Record type to hold the details of an error.

FileEvent

Represents an event which will trigger when there is a changes to listining direcotry.

ListenerConfig

Represents configurations that required for directory listener.

Objects

FileInfo

FileInfo record contains metadata information of a file.

Listeners

Listener

Represents the directory listener endpoint, which is used to listen to a directory in the local file system.

Functions

copy

Copy the file/directory in the old path to the new path.

createDir

Creates a new directory with the specified file name.

createFile

Creates a file in the specified file path.

exists

Reports whether the file or directory exists in the given the path.

getCurrentDirectory

Returns the current working directory.

getFileInfo

Returns the metadata information of the file specified in the file path.

readDir

Reads the directory and returns a list of files and directories inside the specified directory.

remove

Removes the specified file or directory.

rename

Renames(Moves) the old path with the new path.

tempDir

Returns the default directory to use for temporary files.

Constants

INVALID_OPERATION_ERROR

Identifies invalid operation error.

PERMISSION_ERROR

Identifies permission error.

FILE_SYSTEM_ERROR

Identifies file system error.

FILE_NOT_FOUND_ERROR

Identifies file not found error.

Types

Error

Represents file system related errors.

Errors

FileNotFoundError

Represents an error that occurs when the file/directory does not exist at the given filepath.

FileSystemError

Represents an error that occurs when a file system operation fails.

InvalidOperationError

Represents an error that occurs when a file system operation is denied due to invalidity.

PermissionError

Represents an error that occurs when a file system operation is denied, due to the absence of file permission.