io » writeFile(file,content,append)
Description
Like writeFileAsIs(file,content,append)
, this command writes content
to file
,
with an optional flag to append
to existing content. However, this command will also perform data variable
substitution during the file-write operation. This means that if content
contains any ${...}
,
[(EXPRESSION) => ...]
. $(...)
text, such text will be replaced with the value known during the execution.
The writeFileAsIs(file,content,append)
, on the other hand, will not perform
data variable substitution during its file-write operation.
The content
parameter may be a fully qualified file path, a http/https web resource, or text content. Nexial will
resolve the content reference internally. Use the append
parameter to either overwrite (if file
exists) or append
content.
In general, it would be a good idea to derive at a predictable outcome inasmuch as reasonable. However the end-of-line
(EOL) character (a.k.a. newline or nextline) is system-dependent. On Windows, it’s usually a combination of carriage
return (\r
) and line feed (\n
). On *NIX/Mac it’s usually just the line feed (\n
). One can usually generalize this
using the (eol)
syntax and let Nexial figures out the appropriate character(s) to use.
In order to compensate for the differences, Nexial supports a few different ways to handle the EOL characters. Using
the nexial.io.eolConfig
System variable, one can control the EOL
characters to use:
as is
: leave the EOL characters as is; whatever the content in question has is what will be usedplatform
: change the EOL characters according to the system currently running the automation. This is the default behavior.windows
: change the EOL characters to\r\n
.unix
: change the EOL characters to\n
.
For example, perhaps one is producing a file to be consumed by a UNIX process. It may be important to ensure that the
EOL characters is set to unix
. One can define the nexial.io.eolConfig
System variable to unix
- either via the
data file or via base » save(var,value)
command.
Parameters
- file - this parameter if the full path of the file along with file name to which the content has to be written.
- content - this parameter is the content which need to written to the file
- append - this parameter is a boolean value if you want to append the existing value or ignore it.
Example
Script:
Output: