Read File Action Icon

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 | Read from File | Write to File | Synchronize Folders | Concatenate Files

File System - 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 | Read from File | Write to File | Synchronize Folders | Concatenate Files

Description

Reads data from a file (usually a text file) and places the data in a variable so it may be used in subsequent task steps or employed in a repetitive process using appropriate Loop actions.

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)

  1. SOURCE="c:\sourcefolder\file.txt"

  2. SOURCE="filename.txt"

The path and file name of the file containing the data that should be read. This should preferably be an absolute path (full path and file name) file name only (requires use of the Change Folder action).

Populate Variable with Data

Text

Yes

(Empty)

RESULTVARIABLE="theVarName"

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.

Encoding

Text (Options)

No

ANSI

ENCODING="Unicode"

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.

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. This is a design time parameter and therefore contains no markup.

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

(Empty)

MAXBYTES="7777"

Specifies the maximum number of bytes that should be read from the 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.

Populate Variable with number of bytes read

Number

No

(Empty)

BYTESVARIABLE="bytesvar"

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 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.

 

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