Command Reference

Write to Text File

Writes text to a text file.

Action ID: 37
Action Category: Text Files

Settings

File name

The name of the text file to write to.

Data to write

The text to write out to the text file.

TIP

 

You can write the contents of a variable to a text file by using the variable name in the Data to write field.

If file already exists

What to do if the file already exists:

Overwrite file with new data

-

The old file will be erased and the data will be written to create a new file.

Prepend data to start of file

-

The text in Data to write will be added to the beginning of the text file.

Append data to end of file

-

The text in Data to write will be added to the end of the text file.

Return Values

Value
(%LastErrorNum%)

Simple Message
(%LastErrorMsg%)

Verbose Message
(%LastErrorDetails%)

0 (OK)

 

 

1

Could not write to text file.

Error opening file.
<<File name>>

Examples

Example 1

In this example, we will overwrite the existing data in a text file with a new string.

(This will be a common case when working with this action. Often you will read all the text from a file into a variable, perform various actions on the text, and then overwrite the text file with the new text.)

We will overwrite the text in our "readme.txt" file, which is located in our program's main directory, represented by %AppDir%. The text we want to write to the readme.txt file would have been assigned to a custom variable named %ReadmeText% earlier in the setup.

File name: %AppDir%
Data to write: %ReadmeText%
If file already exists: Overwrite with new data

Example 2

In this example, we will add the current date to the end of our "SetupInfo.txt" file.

Note: %Date% is a built-in variable. There are other date variables available as well, including %EuropeanDate%, %ISODate% and %JulianDate%.

File name: %AppDir%\SetupInfo.txt
Data to write: %Date%
If file already exists: Append data to end of file

 

See Also: Alphabetical List of Actions, Categorical List of Actions, On Error tab