Flat (ascii) Files

Version:
2019.3
Last modified: October 09, 2019

The flat file type (.flat) is used with ASCII files (.asc) which contain fixed-length fields and optional line ends to mark the end of records. The actual ASCII data does not contain any information about the structure of fields nor the data types of those fields. For information on data types, see Data Types.

Read and write flat files

Use an Input Data Tool and Output Data Tool to read and write .flat files. If you are reading an unknown file type into Designer and have selected the Read it as a fixed width text file option, see Flat File Layout.

Flat file structure

The .flat file is written in XML and can be modified to describe information about the structure and data types of fields. The root element is flatfile with a version attribute, which must be set to 1. The flatfile element contains the following child elements:

  • file: Declares where the actual flat-ASCII data is located and what kind of properties it has. The file has these attributes:
    • path: The path to the data file. It can be absolute or relative to the description file.
    • eoltype: The kind of line ends that you want to use. Valid options are none, crlf(default is Windows), lf(Unix), and cr(Mac).
    • allowShortLines: Indicates if a record can end before all fields are read. This is valid only for data with line ends. Missing fields will be set to Null. Valid options are true (t) or false (f)(default).
    • allowLongLines: Indicates if there can be extra characters after the last field for the current record. This extra data will be discarded. Valid options are true (t) or false (f)(default).
    • trimWhiteSpace: When this is true, blank characters are trimmed from field data. Valid options are true (t) or false (f).
  • fields: Contains one or many field elements. It has the following attributes:
    • type: The data type of field. Valid types for flat files are Bool, Byte, Int16, Int32, Int64, FixedDecimal, Float, String, and V_String.
    • Byte is an unsigned number between 0 and 255, so the size of the byte is 3 characters. See Data Types for descriptions and examples of these types.
    • name: The name of the field.
    • length: The length of the field.
    • scale: Only used if the field type is FixedDecimal. In that case, this attribute is required.

Example

HTML
  1. <flatfile version="1">
  2.   <file
  3.       path="data.asc"
  4.       eoltype="lf"
  5.       trimWhiteSpace="f"
  6.       allowShortLines="t"
  7.       />
  8.   <fields>
  9.     <field name="KEY " type="String" length="5" />
  10.     <field name="NAME" type="String" length="12" />
  11.     <field name="VALUE" type="Double" length="20" />
  12.   </fields>
  13. </flatfile>
Was This Helpful?

Need something else? Visit the Alteryx Community or contact support.