FileWrite

Writes a string to a specified ASCII or Unicode file. If the file doesn't exist, then the function will create the file.

Function Group Execution Windows Embedded Thin Client
FileWrite File Synchronous Supported Supported Supported

Description

Writes a string to a specified ASCII or Unicode file. If the file doesn't exist, then the function will create the file.

Syntax

FileWrite(strFileName,strWriteText { | ,optNumAppend } )
strFileName
A string value enclosed in quotes, or the name of a String tag that contains the value, specifying the file name.

By default, the file will be written in your project folder (i.e., the folder that contains the file project_name.APP). To write in another folder, specify the complete file path.

strWriteText
A string value enclosed in quotes, or the name of a String tag that contains the value, specifying the text to be written to the file.
optNumAppend
A numerical value, or the name of an Integer tag that contains the value, specifying the text encoding of the file:
Value Description
0 Creates a new ASCII file with the given file name. If the file already exists, then it is overwritten.
1 Appends to an existing ASCII file with the given file name. If the file doesn't exist, then a new file is created.
2 Creates a new Unicode (UTF-16LE) file with the given file name. If the file already exists, then it is overwritten.
3 Appends to an existing Unicode file with the given file name. If the file doesn't exist, then a new file is created.

This is an optional parameter. If any value other than 0 through 3 is given, or if the parameter is not used, then 0 is the default.

Returned value

0 Successful execution.
−1 Invalid parameter(s).
−2 Failed to open file. Disk is write protected or file name is invalid.

Examples

Tag Name Expression
Tag FileWrite( "c: est.txt", "This is a test" )
Tag FileWrite( strFileName, strWriteText )
Tag FileWrite( strFileName, strWriteText, 1 )