File System Adapter
This page explains the Filesystem Adapter in Bridge context. If you were looking for the same information regarding the PAS Designer, refer to Filesystem Adapter in the Designer guide.
With the File System add-on, it is possible to read and write files (even incrementally), and to read and create directories.
Example File (Builder project Add-ons/FileSystem):
<your example path>\Add-ons\FileSystem\uml\fileSystemDyn.xml <your example path>\Add-ons\FileSystem\uml\fileSystemStat.xml |
Common Tasks Using the File System Adapter
Find below a table listing some common tasks you can use the File System Adapter for, and which action to use for which task.
Task | Action | Mode | Important Parameters | Comments |
---|---|---|---|---|
Write a complete file in one action. | write |
| ||
Replace part of a file. | write | position | Writes the data to the file beginning at the specified position. If the file does not exists you'll get the exception FSADM/8 (see Catching Errors). | |
Append data to a file. | append | append |
| |
Write a complete file line by line. | append | overwrite | Use mode overwrite for all appends.
overwrite will only be applied to the first append. All subsequent appends (e.g. in a loop) automatically get mode append. | |
Copy a complete file. | copy Runtime 2020.4 Builder 7.8.0 | Copy a file in one action. Using copy you can even copy huge files because it does not load the complete file into memory. | ||
Manipulate a file and process the file further (e.g. moving it). | Before processing the file further (e.g. moving it), close the file. Otherwise it may be locked. |
Static versus Dynamic Requests
We distinct between static and dynamic requests.
- Static means that the whole backend information (path and name) is defined in the component diagram and is not modified when called within an action. However, this information can be accessed within an action via the so called deployment macros. This is sometimes useful, e. g. when URL parameters must be calculated or known at runtime only (for details refer to Deployment Macros).
- A dynamic call means that the necessary parameters are being specified during the execution of the activity. In the present case, a dynamic usage of the file system adapter means that parameters like the name of a file or a directory are not part of the component diagram, but rather specified in an action and passed on to the file system adapter as an input object. Read more on dynamic file system access on Dynamic File System Access.
Catching Errors
All errors thrown by the File System adapter can be caught as described in Catching Errors.
Domain | Error Code | Description |
---|---|---|
FSADSM | 1 | Failed opening file. |
FSADSM | 3 | Position is invalid. |
FSADSM | 4 | Failed reading file. |
FSADSM | 6 | Failed stating file. |
FSADSM | 7 | The content is smaller than the write size. |
FSADSM | 8 | Failed opening file. |
FSADSM | 9 | Position is invalid. |
FSADSM | 10 | Failed writing file. |
FSADSM | 13 | Failed stating file. |
FSADSM | 14 | Failed renaming entry. |
FSADSM | 16 | Failed creating directory. |
FSADSM | 18 | Failed opening directory. |
FSADSM | 21 | Data missing for write request. |
FSADSM | 22 | Failed creating file. |
FSADSM | 23 | Failed stating entry for removal. |
FSADSM | 25 | Failed opening file. |
FSADSM | 26 | Failed renaming entry. |
FSADSM | 29 | File is not open. |
FSADSM | 31 | Failed getting exact file size. The real size may differ. |
FSADSM | 32 | Name is empty. |
FSADSM | 33 | Path '%s' is outside allowed base directory '%s'. |
FSADSM | 34 | Failed copying entry. |