file

Functions for working with files and directories.

Summary
fileFunctions for working with files and directories.
Exceptions
FileExceptionGeneric file error.
FileException.DirectoryExistsIndicates that a directory already exists when calling mkdir.
FileException.ExistsIndicates that a an attempt was made to create, or overwrite an existing file.
FileException.OpenIndicates that an error occurred when opening a file.
FileException.PathNotFoundIndicates that a path was not found.
FileException.PermissionDeniedIndicates that an operation was denied due to filesystem permisssions.
FileException.WriteIndicates that an error occurred while writing to a file.
Functions
copyCopies a file to a new destination.
copyOverwriteIfExistsCopies a file to a new destination.
deleteDelete a file.
existsCheck to see whether a name exists in the filesystem.
filesGiven a path name, return an array containing the names of the files in that directory.
isDirectorySimilar to exists, but only returns TRUE if the path actually is a directory.
mkdirCreate a new directory with the given name.
pathJoinJoin components of a path using the <Separator> characters appropriate for the OS.
pathSplitSplit a path into directory and name parts.
readBytesRead the contents of a file into Bytes.
readLinesRead the lines of a file into an array of Strings.
removeDirectoryTreeRemove directory tree recursively.
removeEmptyDirectoryRemove an empty directory.
renameRename a file.
symlinkCreate a symlink named newlink that points to target.
writeBytesWrite a complete file from data in Bytes.
writeLinesWrite a complete file from lines of text in an array.

Exceptions

FileException

Generic file error.

FileException.DirectoryExists

Indicates that a directory already exists when calling mkdir.

FileException.Exists

Indicates that a an attempt was made to create, or overwrite an existing file.

FileException.Open

Indicates that an error occurred when opening a file.

FileException.PathNotFound

Indicates that a path was not found.

FileException.PermissionDenied

Indicates that an operation was denied due to filesystem permisssions.

FileException.Write

Indicates that an error occurred while writing to a file.

Functions

copy

DECLARE NATIVE FUNCTION copy(filename: String,
destination: String)

Copies a file to a new destination.  If the destination file already exists, a FileException.Exists is raised, and the file is not copied.

Exceptions

See Also

copyOverwriteIfExists exists delete

Example

TRY
    file.copy("LICENSE.txt", "tmp/Copy_of_LICENSE.txt")
TRAP file.FileException.Exists DO
    print("File copy failed.  Destination file already exists.")
END TRY

copyOverwriteIfExists

DECLARE NATIVE FUNCTION copyOverwriteIfExists(filename: String,
destination: String)

Copies a file to a new destination.  If the destination file exists, it will be overwritten.  If the destination file does not exist, it will be created.

See Also

copy

Example

file.copyOverwriteIfExists("LICENSE.txt", "tmp/Copy_of_LICENSE.txt")

delete

DECLARE NATIVE FUNCTION delete(filename: String)

Delete a file.  This function does not raise an exception if the file does not exist.

Exceptions

exists

DECLARE NATIVE FUNCTION exists(filename: String): Boolean

Check to see whether a name exists in the filesystem.  The name may refer to either a file or a directory.

files

DECLARE NATIVE FUNCTION files(path: String): Array<String>

Given a path name, return an array containing the names of the files in that directory.

isDirectory

DECLARE NATIVE FUNCTION isDirectory(path: String): Boolean

Similar to exists, but only returns TRUE if the path actually is a directory.

mkdir

DECLARE NATIVE FUNCTION mkdir(path: String)

Create a new directory with the given name.

Exceptions

pathJoin

FUNCTION pathJoin( first,
second: String): String

Join components of a path using the <Separator> characters appropriate for the OS.

pathSplit

FUNCTION pathSplit(path: String,
OUT directory,
name: String)

Split a path into directory and name parts.

readBytes

DECLARE NATIVE FUNCTION readBytes(filename: String): Bytes

Read the contents of a file into Bytes.

Exceptions

  • <FileOpenError> - if the file cannot be opened

readLines

DECLARE NATIVE FUNCTION readLines(filename: String): Array<String>

Read the lines of a file into an array of Strings.

Exceptions

  • <FileOpenError> - if the file cannot be opened

removeDirectoryTree

FUNCTION removeDirectoryTree(path: String)

Remove directory tree recursively.

removeEmptyDirectory

DECLARE NATIVE FUNCTION removeEmptyDirectory(path: String)

Remove an empty directory.

rename

DECLARE NATIVE FUNCTION rename(oldname: String,
newname: String)

Rename a file.  This function can also be used to move a file from one directory to another.

Exceptions

  • <PathNotFound> - if the file does not exist

symlink

DECLARE NATIVE FUNCTION symlink(target: String,
newlink: String,
targetIsDirectory: Boolean DEFAULT FALSE)

Create a symlink named newlink that points to target.

Exceptions

  • <PathNotFound> - if the path does not exist

writeBytes

DECLARE NATIVE FUNCTION writeBytes(filename: String,
data: Bytes)

Write a complete file from data in Bytes.

Exceptions

  • <FileOpenError> - if the file cannot be opened
  • <FileWriteError> - if an error occurs during writing

writeLines

DECLARE NATIVE FUNCTION writeLines(filename: String,
data: Array<String>)

Write a complete file from lines of text in an array.

Exceptions

  • <FileOpenError> - if the file cannot be opened
  • <FileWriteError> - if an error occurs during writing
DECLARE NATIVE FUNCTION mkdir(path: String)
Create a new directory with the given name.
DECLARE NATIVE FUNCTION copy(filename: String,
destination: String)
Copies a file to a new destination.
DECLARE NATIVE FUNCTION copyOverwriteIfExists(filename: String,
destination: String)
Copies a file to a new destination.
DECLARE NATIVE FUNCTION delete(filename: String)
Delete a file.
DECLARE NATIVE FUNCTION exists(filename: String): Boolean
Check to see whether a name exists in the filesystem.
DECLARE NATIVE FUNCTION files(path: String): Array<String>
Given a path name, return an array containing the names of the files in that directory.
DECLARE NATIVE FUNCTION isDirectory(path: String): Boolean
Similar to exists, but only returns TRUE if the path actually is a directory.
FUNCTION pathJoin( first,
second: String): String
Join components of a path using the Separator characters appropriate for the OS.
FUNCTION pathSplit(path: String,
OUT directory,
name: String)
Split a path into directory and name parts.
DECLARE NATIVE FUNCTION readBytes(filename: String): Bytes
Read the contents of a file into Bytes.
Bytes.
DECLARE NATIVE FUNCTION readLines(filename: String): Array<String>
Read the lines of a file into an array of Strings.
Unicode string.
FUNCTION removeDirectoryTree(path: String)
Remove directory tree recursively.
DECLARE NATIVE FUNCTION removeEmptyDirectory(path: String)
Remove an empty directory.
DECLARE NATIVE FUNCTION rename(oldname: String,
newname: String)
Rename a file.
DECLARE NATIVE FUNCTION symlink(target: String,
newlink: String,
targetIsDirectory: Boolean DEFAULT FALSE)
Create a symlink named newlink that points to target.
DECLARE NATIVE FUNCTION writeBytes(filename: String,
data: Bytes)
Write a complete file from data in Bytes.
DECLARE NATIVE FUNCTION writeLines(filename: String,
data: Array<String>)
Write a complete file from lines of text in an array.
Indicates that a an attempt was made to create, or overwrite an existing file.
Indicates that an operation was denied due to filesystem permisssions.
Indicates that a directory already exists when calling mkdir.
Indicates that a path was not found.
Close