Write File Action Icon

Write To File

Declaration

<AMFILEWRITE FILE="text" APPEND="YES/NO" RESULTVARIABLE="text">text</AMFILEWRITE>

See Also

Calculate File Checksum | Change Folder | Concatenate Files | Copy File | Create Folder | Delete File | Get File(s) information | Join File | Move File | Read from File | Remove Folder | Rename File | Rename Folder

File System - Write To File

Declaration

<AMFILEWRITE FILE="text" APPEND="YES/NO" RESULTVARIABLE="text">text</AMFILEWRITE>

See Also

Change Folder | Concatenate Files | Copy File | Create Folder | Delete File | Get File(s) information | Join File | Read from File

Description

Writes the specified text string to a file. If the file does not exist, it will be created at runtime. If the files exists and already contains data, this action can be set to either overwrite the current data or append the new data directly below the existing one. Execution is performed in the background, therefore, the file does not have to be open in order for data to be written to it.

Practical Usage

Commonly used to write specific text onto a new text file or modify an existing text file by appending text to existing data or writing new text over the original data contained in that file.

Parameters

General Properties

Property

Type

Req'd

Default

Markup

Description

File

Text

Yes

(Empty)

FILE="c:\sourcefolder\file.txt"

The text file that the data should be written to. If the file does not exist, it will be created and written to at runtime. As with every text parameter, if the data you wish to write to is contained in a variable, simply enter the variable name surrounded by percentage signs to resolve it to it's contents at runtime (i.e. %VarName%).

Encoding

Text (Options)

No

Unicode

ENCODING="Unicode big endian"

Specifies the character encoding method to use. The available options are:

  • UTF-8 - Uses variable byte to store a Unicode. UTF-8 is suitable for using on Internet, networks or some kind of applications that needs to use slow connection.

  • Unicode (default) - A universal character set that defines the characters included in a majority of the languages of the world.

  • Unicode Big Endian - Also known as UTF-16BE."Big Endian"  means that the high-order byte of the number is stored in memory at the lowest address, and the low-order byte at the highest address.

  • ANSI -A character encoding of the Latin alphabet, used by default in the legacy components of MS Windows English and some other Western languages.

Method

Yes/No

No

Yes

APPEND="NO"

Indicates how the data should be written. The available options are:

  • Overwrite File - Existing data will be overwritten.

  • Append at the end of the file (default) - The data will be written to the end of the file as a new line.

Data to write

Text

Yes

(Empty)

a)DATA="The text to write"

b)DATA="%varName%"

Specifies the data to write to the file. As with every text parameter, if the data you wish to write is contained in a variable, simply enter the variable name surrounded by percentage signs to resolve it to it's contents at runtime (i.e. %VarName%).

Populate variable with the number of bytes written

Text

No

(Empty)

RESULTVARIABLE="totalBytes"

The name of the variable to populate with the number of bytes that were written to the file.

Description Properties

The Description tab allows you to customize the text description of any step as it appears in the Task Builder's Steps Pane.

More on setting custom step description

Error Causes Properties

The Error Causes tab properties lets you instruct a task step to react only to specific errors or ignore certain errors that should cause it to fail.

More on Error Causes properties

On Error Properties

The On Error tab properties lets you determine what the task should do if a particular step encounters an error as defined in the Error Causes properties.

More about On Error properties

Additional Notes

Expressions, Variables & Functions

A percent sign is used as a special character in AutoMate to indicate the beginning and end of an expression. This allows variables, functions and other expressions to be entered in any text parameter of a task's properties. For example: %1+1% inside a task will resolve to 2 at runtime. A more elaborate example is %FileDateTime(myFile)% which results to the date/time of myFile. To help construct expressions, you can open Expression Builder by clicking the Insert Expression (%) button or by pressing F2.

More on expressions

More on variables

More on functions

More on extended functions
More on the expression builder

Example

NOTE: The code below can be copied and pasted directly into the Steps pane of the Task Builder.

 

Description: This task writes contents to C:\Temp\TestFile.txt using the Write to File action and reads the contents into a variable using a Read from File action. The contents are then displayed in a message box.

 

<AMVARIABLE NAME="TheData"></AMVARIABLE>

<AMFILEWRITE FILE="C:\Temp\TestFile.txt" APPEND="NO">I love AutoMate!!!</AMFILEWRITE>

<AMFILEREAD FILE="C:\Temp\TestFile.txt" RESULTVARIABLE="theData" />

<AMSHOWDIALOG>%TheData%</AMSHOWDIALOG>

 

↑ Top of Page