17. File Functions
You use the file management APL functions to manage files in
. These functions include:readFileBinary
fileDelete
fileMove
fileListFiles
fileListDirectories
Note!
These functions can only be used for the directories in your local file system.
readFileBinary
Reads a binary file and returns its contents in the software's bytearray data format.
bytearray readFileBinary (string path )
Parameter | Description |
---|---|
| The physical path and name of the file |
Returns | The contents as a |
fileDelete
The fileDelete command takes the absolute path of a file and deletes that file.
If the delete is successful, null is returned. If there is an error, an error string is returned.
string fileDelete (string fileName )
Parameter | Description |
---|---|
| The absolute path to the file to delete |
Returns | Null if the deletion was successful, otherwise an error string |
fileMove
The fileMove command takes the path to the file to be moved, and the path to the new destination.
If the move is successful, null is returned. If there is an error, an error string is returned.
string fileMove (string fileName , string newFileName )
Parameter | Description |
---|---|
| The absolute path to the file you want to move |
| The absolute path to the new destination of the file (e.g. "/home/files/20110505/movedFile.csv"). |
Returns | Null if the file was moved successfully, otherwise an error string |
fileListFiles
The fileListFiles command lists all files in a given directory.
The command only returns actual files from the directory, it does not return any sub-directories or files from sub-directories. If there are no files in the given directory, an empty list is returned. If there is an error, null is returned.
list<string> fileListFiles (string directory, regex filter (optional))
Parameter | Description |
---|---|
| The absolute path to the directory for which you want to list files |
filter | You can enter a regular expression to filter out which files you want to list. |
Returns | A list (may be empty) of the files in the given directory, or null if there is an error |
Note!
The files will not necessarily be listed in alphabetical, or any other specific order.
fileListDirectories
The fileListDirectories command lists all subdirectories in a given directory.
The command only returns subdirectories in the given directory, it does not return files or subdirectories to the subdirectories. If there are no directories in the given directory, an empty list is returned. If there is an error, null is returned.
list<string> fileListDirectories (string directory , regex filter (optional))
Parameter | Description |
---|---|
| The absolute path to the directory for which you want to list subdirectories |
filter | You can enter a regular expression to filter out which directories you want to list. |
Returns | A list (may be empty) of the directories in the given directory, or null if there is an error |