Read From File

Declaration

<AMFILEREAD FILE="text" RESULTVARIABLE="text" MAXBYTES="number" BYTESVARIABLE="text" NEWPOSITIONVARIABLE="text" POSITION="number" />

See Also

Split File, Move File, Create Folder, Delete File, Delete Folder, Rename Folder, Remove Folder, Touch File, Set Attributes, Write to File, Synchronize Folders, Concatenate Files

Description

Reads data from a file (usually a text file) and places the data in a variable.

Practical Usage

Commonly used to read data from a text file. For example, a user may wish to read a list of names from a text file and use that data with the Send Keystrokes action to send the data to another application or use the Write to File action to write the data to another file. To do this, start with the Create Variable action. Then, use a Read From File action to place all the data into a variable. Thereafter, use the Loop List action to loop through the data. Inside the loop use the Send Keystrokes or Write to File action.

Parameters

General Properties

Property

Type

Required

Default

Markup

Description

File

Text

Yes

(Empty)

a)SOURCE="c:\sourcefolder\file.txt"
b)SOURCE="filename.txt"

The path and file name of the file containing the data that should be read. This can be a fully qualified path and file name (preferred) or a file name only (requires use of the Change Folder action).

Populate Variable with Data

Text

Yes

(Empty)

a)DEST="c:\destfolder\file.txt"
b)DEST="c:\destfolder\*.*"
 

The name of the variable to populate with the text contents of the file. The variable must be created in a previous step using the Create Variable action.

Read Entire File

Null

Null

Null

Null

If enabled, the entire contents of the file will be read to a variable, If this option is selected, the Read File Partially parameter is ignored. This parameter is enabled by default.

Read File Partially

Null

Null

Null

Null

The default behavior is to read the entire file. However, you can set this action to read only a section of the file by enabling the Read File Partially option. This is useful if the file being read is particularly large in size. If this option is enabled, other parameters become active.

Read from position

Number

No

(Empty)

POSITION="34"

The position in the text file that this action should start reading from. Using this option along with the Limit number of bytes read to parameter can limit the amount of system memory used, thus speeding up execution.

Limit number of bytes read to

Number

No

 

MAXBYTES="7777"

If enabled, specifies the maximum number of bytes that should be read from the text file. This limit is important because it prevents AutoMate from taking up a virtually unlimited amount of system memory depending on the size of the file. Text beyond this amount of space is truncated.

Populate variable with new position in file.

Number

No

(Empty)

NEWPOSITIONVARIABLE="positionvar"

The name of the variable to populate with the new position in the file. This allows you to retrieve data from a large file in sections.

Advanced Properties

Property

Type

Required

Default

Markup

Description

Populate Variable with number of bytes read

Number

Yes

(Empty)

BYTESVARIABLE="bytesvar"

If enabled, specifies the name of the variable to populate with the total number of bytes read.

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 allows you to 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 and Functions

All text fields allow the use of expressions such as variables, functions or AutoMate extended functions, which can be entered by surrounding the expression in percentage signs (example: %FileDateTime(myVar)% or %myVar%, %Left('Text',2)%). To help construct these expressions, you can open Expression Builder from these fields by clicking the Insert Expression (%) button or by pressing F2.

More on expressions

More on variables

More on function

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.

 

Sample Task 1 - This sample task reads data from "C:\Temp\monthlyreport.txt" starting at position 120 and reading 2360 bytes. The variable named "datavar" is populated with the text. The variable "bytesvar" is populated with the with the number of bytes read. And the variable named "positionvar" is populated with the new position in the file after reading. The last step of the task writes the variable contents to a new file.

 

 

<AMVARIABLE NAME="datavar"></AMVARIABLE>

<AMVARIABLE NAME="bytesvar"></AMVARIABLE>

<AMVARIABLE NAME="positionvar"></AMVARIABLE>

<AMFILEREAD FILE="C:\Temp\monthlyreport.txt" RESULTVARIABLE="datavar" MAXBYTES="2360" BYTESVARIABLE="bytesvar" NEWPOSITIONVARIABLE="positionvar" POSITION="120" />

<AMFILEWRITE FILE="c:\temp\statusfile.txt">File contents - %datavar%

Number of bytes read - %bytesvar%

Current position in file - %positionvar%</AMFILEWRITE>

 

 

Sample Task 2 - 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.

 

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

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

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

<AMMESSAGEBOX>Contents of text file:&#xD;&#xA;&#xD;&#xA;%TheData%</AMMESSAGEBOX>

 

↑ Top of Page