Writes the text string specified 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. 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.
Declaration
<AMFILEWRITE FILE="text" APPEND="YES/NO" RESULTVARIABLE="text">text</AMFILEWRITE>
Example
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>
See Also: Split File, Move File, Create Folder, Delete File, Delete Folder, Rename Folder, Remove Folder, Touch File, Set Attributes, Read from File, Write to File, Synchronize Folders, Concatenate Files
Property |
Type |
Required |
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 want to write to is contained in a variable, enter the variable name surrounded by percentage signs to resolve it to it's contents at runtime (i.e. %VarName%). |
Method |
Yes/No |
No |
Yes |
APPEND="NO" |
Indicates how the data should be written. The available options are:
|
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 want to write is contained in a variable, enter the variable name surrounded by percentage signs to resolve it to it's contents at runtime (i.e. %VarName%). |
Property |
Type |
Required |
Default |
Markup |
Description |
Populate variable with the number of bytes written |
Text |
Yes |
(Empty) |
RESULTVARIABLE="totalBytes" |
The name of the variable to populate with the number of bytes that were written to the file. |