File and Directory Functions

The Automation1 controller supports a hierarchical file system with directories and files. This is where the controller’s AeroScript programs and libraries, data collection files, and user files exist. The File and Directory functions supply an easy way to interact with the file system, including the ability to read and write file contents.

WARNING: The File and Directory functions do not execute in real time. The time that it takes for the command to execute is different for different PC configurations. Aerotech recommends that you use these functions only in code that is not time-critical.

In the controller file system, the file and directory paths obey these rules:

  • File and directory names are case-insensitive.
  • File system paths must use the forward slash character, ('/'), as the file separator.
  • Absolute file system paths must start with a forward slash character ('/').

  • Relative file system paths do not start with a forward slash character ('/'). These paths are relative to the program that is currently executing on the task.

For more information, see Controller File System.

IMPORTANT: When you use a relative path in an immediate command or in the command queue, it is always applied as an absolute path. To make sure that the path points to the correct file, Aerotech recommends that you use only absolute paths in immediate commands and commands in the command queue.

Handles

The handle is a native data type used to interact with an external resource, including files. With a native data type, the AeroScript compiler can supply a well-defined interface for file operations with improved type-checking. For more information, refer to Fundamental Handle Data Type on the Data Types and Variables page.

Open and Close a Handle

You must open a handle before you can use it to communicate with a file. After you open the handle, you can pass it to other file operation functions to do many supported operations.

The controller supports interacting with files in the modes that follow:

  • Binary mode: Exposes the raw bytes of the file, which lets you do low-level memory operations. For more information, see the Binary Files section on this page.
  • Text mode: Automatically interprets the file as a sequence of human-readable characters. For more information, see the Text Files section on this page.

function FileClose($file as handle)

Closes the specified file.

Arguments

$file  A handle that represents an open file.

function FileOpenBinary($controllerFileName as string, $mode as FileMode) as handle

Opens the specified file in binary mode. Use this function to read and modify the file as a sequence of bytes interpreted as integer or floating point data.

Arguments

$controllerFileName  The path, file name, and extension of the file on the controller file system to open.

$mode  The mode with which to open the file. If $mode is specified as FileMode.Overwrite or FileMode.Append, and $controllerFileName contains directories that do not exist, then the directories will be created.

Returns

A handle used to access the file.

function FileOpenText($controllerFileName as string, $mode as FileMode) as handle

Opens the specified file in text mode. Use this function to read and modify the file as UTF-8 encoded text.

Arguments

$controllerFileName  The path, file name, and extension of the file on the controller file system to open.

$mode  The mode with which to open the file. If $mode is specified as FileMode.Overwrite or FileMode.Append, and $controllerFileName contains directories that do not exist, then the directories will be created.

Returns

A handle used to access the file.

Use the FileMode enumeration to select the file permission mode you want to use.

File Position

After you open a file, it might be necessary to navigate through the file to read information or write new data at a specific location. The functions that follow supply an easy way to navigate using file byte offsets.

function FileGetByteOffset($file as handle) as integer

Gets the current byte offset for reading and writing in the specified file.

Arguments

$file  A handle that represents an open file.

Returns

The current reading or writing offset of the file.

function FileSetByteOffset($file as handle, $offset as integer)

Sets the current byte offset for reading and writing in the specified file.

Arguments

$file  A handle that represents an open file.

$offset  The reading or writing offset to set for the file.

function FileIsEndOfFile($file as handle) as integer

Returns whether the current reading offset is at the end of the file.

Arguments

$file  A handle that represents an open file.

Returns

1 if the current reading offset is at the end of the file. 0 otherwise.

function FileSize($file as handle) as integer

Returns the size of the specified file.

Arguments

$file  A handle that represents an open file.

Returns

The size, in bytes, of the specified file.

Text Files

When a file is in text mode, AeroScript interprets the raw bytes of the file using the UTF-8 encoding. Thus, you can read entire lines from the file until you find a newline character or you find a custom delimiter. And, you can easily write AeroScript strings at the current file location. For information on how to navigate in a file from an AeroScript program, see File Position on this page.

Program Example

// Open a file for writing. If the file already exists, its contents will be overwritten.
var $myTextFileHandle as handle
$myTextFileHandle = FileOpenText("/MyFiles/MyTextFile.txt", FileMode.Overwrite)

// Write text.
FileTextWriteString($myTextFileHandle, "This is the first line.\n")
FileTextWriteString($myTextFileHandle, "This is the second line.\n")


// Close and save the file.
FileClose($myTextFileHandle)


/* Contents of MyTextFile.txt:
This is the first line.
This is the second line.
*/

// Open a file for reading only.
$myTextFileHandle = FileOpenText("MyFiles/MyTextFile.txt", FileMode.Read)

// Read and show the first line.
var $s as string
$s = FileTextReadLine($myTextFileHandle)
AppMessageDisplay($s)
				
// Read and show the second line.
AppMessageDisplay(FileTextReadLine($myTextFileHandle))

// Close the file.

FileClose($myTextFileHandle)

function FileTextReadLine($file as handle) as string

Returns a line from the specified text file.

Arguments

$file  A handle that represents an open text file.

Returns

A string that represents the next line in the specified text file. This string will not contain line endings.

function FileTextReadString($file as handle, $delimiter as string) as string

Returns a string from the specified text file.

Arguments

$file  A handle that represents an open text file.

$delimiter  The delimiter used to identify where to stop reading.

Returns

A string from the specified text file. This string will not contain the specified delimiter.

IMPORTANT: When you specify a delimiter to the FileTextReadString() function, you cannot use an empty delimiter or a delimiter that includes the null-terminator.

function FileTextWriteString($file as handle, $value as string)

Writes a string to a text file.

Arguments

$file  A handle that represents an open text file.

$value  The string value to write to the text file.

Binary Files

When you operate on binary files, you must determine how the raw bytes of the file are to be interpreted. AeroScript supplies individual functions to access the current file location based on the specified underlying data type. And, you can use the array-based functions to access contiguous sequences of the file. For more information on file location, see File Position on this page.

Supported data types:

  • Float32 - IEEE 754 single-precision floating point
  • Float64 - IEEE 754 double-precision floating point
  • Int8 - signed 8-bit integer
  • Int16 - signed 16-bit integer
  • Int32 - signed 32-bit integer
  • Int64 - signed 64-bit integer
  • Uint8 - unsigned 8-bit integer
  • Uint16 - unsigned 16-bit integer
  • Uint32 - unsigned 32-bit integer

Program Example

// Open a file for writing. If the file already exists, its contents will be overwritten.
var $myBinaryFileHandle as handle
$myBinaryFileHandle = FileOpenBinary("MyFiles/MyBinaryFile.bin", FileMode.Overwrite)

// Write a 32-bit floating point value.
FileBinaryWriteFloat32($myBinaryFileHandle, 1.234)

// Write an array of 64-bit integrers to the file.
FileBinaryWriteInt64Array($myBinaryFileHandle, [1, 2, 3, 4, 5], 5)

// Close and save the file.
FileClose($myBinaryFileHandle)

/* Contents of MyBinaryFile.txt:
b6f3 9d3f 0100 0000 0000 0000 0200 0000
0000 0000 0300 0000 0000 0000 0400 0000
0000 0000 0500 0000 0000 0000 
*/

// Open a file for reading only.
$myBinaryFileHandle = FileOpenBinary("MyFiles/MyBinaryFile.bin", FileMode.Read)

// Read the first 4 bytes and interpet the data as a 32-bit floating point value.
AppMessageDisplay(RealToString(FileBinaryReadFloat32($myBinaryFileHandle))) // Displays "1.234"

// Read the next 40 bytes of data and interpet the data as an array of 5 64-bit integers.
var $array[5] as integer
FileBinaryReadInt64Array($myBinaryFileHandle, $array, 5)
AppMessageDisplay(IntegerToString($array[0] + $array[1] + $array[2] + $array[3] + $array[4]) ) // Displays "15"

// Close the file.
FileClose($myBinaryFileHandle)

Reading Binary Files

function FileBinaryReadFloat32($file as handle) as real

Returns the next 4 bytes of a binary file interpreted as a 32-bit floating point value.

Arguments

$file  A handle that represents an open binary file.

Returns

The 32-bit floating-point value.

function FileBinaryReadFloat32Array($file as handle, ref $values[] as real, $numElements as integer) as integer

Interprets an array of bytes of a binary file as an array of 32-bit floating point values and returns the number of elements retrieved.

Arguments

$file  A handle that represents an open binary file.

ref $values  The array to store the retrieved values in.

$numElements  The maximum number of values to read from the file.

Returns

The number of 32-bit floating-point values read.

function FileBinaryReadFloat64($file as handle) as real

Returns the next 8 bytes of a binary file interpreted as a 64-bit floating point value.

Arguments

$file  A handle that represents an open binary file.

Returns

The 64-bit floating-point value.

function FileBinaryReadFloat64Array($file as handle, ref $values[] as real, $numElements as integer) as integer

Interprets an array of bytes of a binary file as an array of 64-bit floating point values and returns the number of elements retrieved.

Arguments

$file  A handle that represents an open binary file.

ref $values  The array to store the retrieved values in.

$numElements  The maximum number of values to read from the file.

Returns

The number of 64-bit floating-point values read.

function FileBinaryReadInt16($file as handle) as integer

Returns the next 2 bytes of a binary file interpreted as a 16-bit signed integer value.

Arguments

$file  A handle that represents an open binary file.

Returns

The 16-bit signed integer value.

function FileBinaryReadInt16Array($file as handle, ref $values[] as integer, $numElements as integer) as integer

Interprets an array of bytes of a binary file as an array of 16-bit signed integer values and returns the number of elements retrieved.

Arguments

$file  A handle that represents an open binary file.

ref $values  The array to store the retrieved values in.

$numElements  The maximum number of values to read from the file.

Returns

The number of 16-bit signed integer values read.

function FileBinaryReadInt32($file as handle) as integer

Returns the next 4 bytes of a binary file interpreted as a 32-bit signed integer value.

Arguments

$file  A handle that represents an open binary file.

Returns

The 32-bit signed integer value.

function FileBinaryReadInt32Array($file as handle, ref $values[] as integer, $numElements as integer) as integer

Interprets an array of bytes of a binary file as an array of 32-bit signed integer values and returns the number of elements retrieved.

Arguments

$file  A handle that represents an open binary file.

ref $values  The array to store the retrieved values in.

$numElements  The maximum number of values to read from the file.

Returns

The number of 32-bit signed integer values read.

function FileBinaryReadInt64($file as handle) as integer

Returns the next 8 bytes of a binary file interpreted as a 64-bit signed integer value.

Arguments

$file  A handle that represents an open binary file.

Returns

The 64-bit signed integer value.

function FileBinaryReadInt64Array($file as handle, ref $values[] as integer, $numElements as integer) as integer

Interprets an array of bytes of a binary file as an array of 64-bit signed integer values and returns the number of elements retrieved.

Arguments

$file  A handle that represents an open binary file.

ref $values  The array to store the retrieved values in.

$numElements  The maximum number of values to read from the file.

Returns

The number of 64-bit signed integer values read.

function FileBinaryReadInt8($file as handle) as integer

Returns the next byte of a binary file interpreted as an 8-bit signed integer value.

Arguments

$file  A handle that represents an open binary file.

Returns

The 8-bit signed integer value.

function FileBinaryReadInt8Array($file as handle, ref $values[] as integer, $numElements as integer) as integer

Interprets an array of bytes of a binary file as an array of 8-bit signed integer values and returns the number of elements retrieved.

Arguments

$file  A handle that represents an open binary file.

ref $values  The array to store the retrieved values in.

$numElements  The maximum number of values to read from the file.

Returns

The number of 8-bit signed integer values read.

function FileBinaryReadUInt16($file as handle) as integer

Returns the next 2 bytes of a binary file interpreted as a 16-bit unsigned integer value.

Arguments

$file  A handle that represents an open binary file.

Returns

The 16-bit unsigned integer value.

function FileBinaryReadUInt16Array($file as handle, ref $values[] as integer, $numElements as integer) as integer

Interprets an array of bytes of a binary file as an array of 16-bit unsigned integer values and returns the number of elements retrieved.

Arguments

$file  A handle that represents an open binary file.

ref $values  The array to store the retrieved values in.

$numElements  The maximum number of values to read from the file.

Returns

The number of 16-bit unsigned integer values read.

function FileBinaryReadUInt32($file as handle) as integer

Returns the next 4 bytes of a binary file interpreted as a 32-bit unsigned integer value.

Arguments

$file  A handle that represents an open binary file.

Returns

The 32-bit unsigned integer value.

function FileBinaryReadUInt32Array($file as handle, ref $values[] as integer, $numElements as integer) as integer

Interprets an array of bytes of a binary file as an array of 32-bit unsigned integer values and returns the number of elements retrieved.

Arguments

$file  A handle that represents an open binary file.

ref $values  The array to store the retrieved values in.

$numElements  The maximum number of values to read from the file.

Returns

The number of 32-bit unsigned integer values read.

function FileBinaryReadUInt8($file as handle) as integer

Returns the next byte of a binary file interpreted as an 8-bit unsigned integer value.

Arguments

$file  A handle that represents an open binary file.

Returns

The 8-bit unsigned integer value.

function FileBinaryReadUInt8Array($file as handle, ref $values[] as integer, $numElements as integer) as integer

Interprets an array of bytes of a binary file as an array of 8-bit unsigned integer values and returns the number of elements retrieved.

Arguments

$file  A handle that represents an open binary file.

ref $values  The array to store the retrieved values in.

$numElements  The maximum number of values to read from the file.

Returns

The number of 8-bit unsigned integer values read.

To determine if the floating-point values returned by some of these functions are valid, specify the values to the RealIsInfinity() or the RealIsNan() functions.

Writing Binary Files

function FileBinaryWriteFloat32($file as handle, $value as real)

Converts the specified value to its 32-bit floating-point binary representation and writes it to the specified file.

Arguments

$file  A handle that represents an open binary file.

$value  The value to write to the file.

function FileBinaryWriteFloat32Array($file as handle, $values[] as real, $numElements as integer)

Converts the specified array of values to an array of 32-bit floating-point values in binary representation and writes it to the specified file.

Arguments

$file  A handle that represents an open binary file.

$values  The values to write to the file.

$numElements  The number of values to write to the file.

function FileBinaryWriteFloat64($file as handle, $value as real)

Converts the specified value to its 64-bit floating-point binary representation and writes it to the specified file.

Arguments

$file  A handle that represents an open binary file.

$value  The value to write to the file.

function FileBinaryWriteFloat64Array($file as handle, $values[] as real, $numElements as integer)

Converts the specified array of values to an array of 64-bit floating-point values in binary representation and writes it to the specified file.

Arguments

$file  A handle that represents an open binary file.

$values  The values to write to the file.

$numElements  The number of values to write to the file.

function FileBinaryWriteInt16($file as handle, $value as integer)

Converts the specified value to its 16-bit signed integer binary representation and writes it to the specified file.

Arguments

$file  A handle that represents an open binary file.

$value  The value to write to the file.

function FileBinaryWriteInt16Array($file as handle, $values[] as integer, $numElements as integer)

Converts the specified array of values to an array of 16-bit signed integer values in binary representation and writes it to the specified file.

Arguments

$file  A handle that represents an open binary file.

$values  The values to write to the file.

$numElements  The number of values to write to the file.

function FileBinaryWriteInt32($file as handle, $value as integer)

Converts the specified value to its 32-bit signed integer binary representation and writes it to the specified file.

Arguments

$file  A handle that represents an open binary file.

$value  The value to write to the file.

function FileBinaryWriteInt32Array($file as handle, $values[] as integer, $numElements as integer)

Converts the specified array of values to an array of 32-bit signed integer values in binary representation and writes it to the specified file.

Arguments

$file  A handle that represents an open binary file.

$values  The values to write to the file.

$numElements  The number of values to write to the file.

function FileBinaryWriteInt64($file as handle, $value as integer)

Converts the specified value to its 64-bit signed integer binary representation and writes it to the specified file.

Arguments

$file  A handle that represents an open binary file.

$value  The value to write to the file.

function FileBinaryWriteInt64Array($file as handle, $values[] as integer, $numElements as integer)

Converts the specified array of values to an array of 64-bit signed integer values in binary representation and writes it to the specified file.

Arguments

$file  A handle that represents an open binary file.

$values  The values to write to the file.

$numElements  The number of values to write to the file.

function FileBinaryWriteInt8($file as handle, $value as integer)

Converts the specified value to its 8-bit signed integer binary representation and writes it to the specified file.

Arguments

$file  A handle that represents an open binary file.

$value  The value to write to the file.

function FileBinaryWriteInt8Array($file as handle, $values[] as integer, $numElements as integer)

Converts the specified array of values to an array of 8-bit signed integer values in binary representation and writes it to the specified file.

Arguments

$file  A handle that represents an open binary file.

$values  The values to write to the file.

$numElements  The number of values to write to the file.

function FileBinaryWriteUInt16($file as handle, $value as integer)

Converts the specified value to its 16-bit unsigned integer binary representation and writes it to the specified file.

Arguments

$file  A handle that represents an open binary file.

$value  The value to write to the file.

function FileBinaryWriteUInt16Array($file as handle, $values[] as integer, $numElements as integer)

Converts the specified array of values to an array of 16-bit unsigned integer values in binary representation and writes it to the specified file.

Arguments

$file  A handle that represents an open binary file.

$values  The values to write to the file.

$numElements  The number of values to write to the file.

function FileBinaryWriteUInt32($file as handle, $value as integer)

Converts the specified value to its 32-bit unsigned integer binary representation and writes it to the specified file.

Arguments

$file  A handle that represents an open binary file.

$value  The value to write to the file.

function FileBinaryWriteUInt32Array($file as handle, $values[] as integer, $numElements as integer)

Converts the specified array of values to an array of 32-bit unsigned integer values in binary representation and writes it to the specified file.

Arguments

$file  A handle that represents an open binary file.

$values  The values to write to the file.

$numElements  The number of values to write to the file.

function FileBinaryWriteUInt8($file as handle, $value as integer)

Converts the specified value to its 8-bit unsigned integer binary representation and writes it to the specified file.

Arguments

$file  A handle that represents an open binary file.

$value  The value to write to the file.

function FileBinaryWriteUInt8Array($file as handle, $values[] as integer, $numElements as integer)

Converts the specified array of values to an array of 8-bit unsigned integer values in binary representation and writes it to the specified file.

Arguments

$file  A handle that represents an open binary file.

$values  The values to write to the file.

$numElements  The number of values to write to the file.

To determine if the floating-point values returned by some of these functions are valid, specify the values to the RealIsInfinity() or the RealIsNan() functions.

Directories

Use the Directory functions to make changes to the controller file system. This includes the ability to copy, delete, and move files. These are the other ways you can get access to the controller file system:

  • In Automation1 Studio, in the Configure workspace under Controller, select Controller Files.

  • In Automation1 Console, use the file command.

function DirectoryCount($controllerDirectory as string) as integer

Returns the number of subdirectories within the specified directory.

Arguments

$controllerDirectory  The path and directory name of the directory on the controller file system to count subdirectories.

Returns

The number of subdirectories within the specified directory.

function DirectoryFileCopy($controllerSourceFileName as string, $controllerDestinationFileName as string)

Copy the specified file.

Arguments

$controllerSourceFileName  The path, file name, and extension of the file on the controller file system to copy.

$controllerDestinationFileName  The path, file name, and extension of the new location of the file on the controller file system.

function DirectoryFileCount($controllerDirectory as string) as integer

Returns the number of files within the specified directory.

Arguments

$controllerDirectory  The path and directory name of the directory on the controller file system from which to count files.

Returns

The number of files within the specified directory.

function DirectoryFileDelete($controllerFileName as string)

Deletes the specified file.

Arguments

$controllerFileName  The path, file name, and extension of the file on the controller file system to delete.

function DirectoryFileExists($controllerFileName as string) as integer

Returns whether the specified file exists.

Arguments

$controllerFileName  The path, file name, and extension of the file on the controller file system to check the existence of.

Returns

1 if the specified file exists. 0 otherwise.

function DirectoryFileGetFileName($controllerDirectory as string, $index as integer) as string

Returns the name of the file with the specified index within the specified directory.

Arguments

$controllerDirectory  The path and directory name of the directory on the controller file system from which to get the name of a file.

$index  The alphabetical index, starting at 0, of the file within the directory.

Returns

The name of the file with the specified index within the specified directory.

function DirectoryFileMove($controllerSourceFileName as string, $controllerDestinationFileName as string)

Moves the specified file.

Arguments

$controllerSourceFileName  The path, file name, and extension of the file on the controller file system to move.

$controllerDestinationFileName  The path, file name, and extension of the new location of the file on the controller file system.

function DirectoryGetName($controllerDirectory as string, $index as integer) as string

Returns the name of the subdirectory with the specified index within the specified directory.

Arguments

$controllerDirectory  The path and directory name of the directory on the controller file system from which to get the name of a subdirectory.

$index  The alphabetical index, starting at 0, of the subdirectory within the directory.

Returns

The name of the subdirectory with the specified index within the specified directory.

File INI

INI files contain values that correspond to a specific key. You can put these keys into sections for organization. Use the FileIni functions to do work with INI files in UTF-8 encoding. This includes the ability to read a value, modify or create a new value, search to see if a section exists, and delete a section or key.

When you use File INI, make sure that you know the important information that follows:

  • Sections and keys are case-insensitive.
  • Sections and keys cannot include whitespace.
  • You cannot have duplicate sections, but you can have nested sections.
  • You cannot have duplicate keys. You can have two or more of the same key if each one belongs to a different section.
  • You cannot have multi-line values.
  • Each time the INI file is modified with a FileIni function, the file will try to adjust itself to maintain two new lines of space between sections.

function FileIniDeleteSection($controllerFileName as string, $section as string) as integer

Deletes the specified section from the INI file if the specified section exists.

Arguments

$controllerFileName  The path, file name, and extension of the INI file on the controller file system to open.

$section  The section to delete. Specify an empty string to delete all keys that do not belong to a section.

Returns

If the specified section was deleted, returns 1. Otherwise, returns 0.

function FileIniDeleteKey($controllerFileName as string, $section as string, $key as string) as integer

Deletes the specified key from the INI file if the specified key exists.

Arguments

$controllerFileName  The path, file name, and extension of the INI file on the controller file system to open.

$section  The section in which the key is located. Specify an empty string if the key does not belong to a section.

$key  The key to delete.

Returns

If the specified key was deleted, returns 1. Otherwise, returns 0.

function FileIniFindSection($controllerFileName as string, $section as string) as integer

Finds if the specified section exists in the INI file.

Arguments

$controllerFileName  The path, file name, and extension of the INI file on the controller file system to open.

$section  The section to search for. Specify an empty string to find if any keys that do not belong to a section exist.

Returns

If the section exists, returns 1. Otherwise, returns 0.

function FileIniReadValue($controllerFileName as string, $section as string, $key as string, $defaultValue as string) as string

Returns the value that belongs to the key in the INI file. If the section or key does not exist, it returns the value specified by $defaultValue.

Arguments

$controllerFileName  The path, file name, and extension of the INI file on the controller file system to open.

$section  The section in which the key is located. Specify an empty string if the key does not belong to a section.

$key  The key from which to retrieve the value.

$defaultValue  The default value to return if the key does not exist.

Returns

Returns the value as a string. If the key does not exist, it returns the value specified by $defaultValue.

function FileIniWriteValue($controllerFileName as string, $section as string, $key as string, $value as string)

Writes the specified value to the specified key in the INI file. If the INI file, section, or key does not exist, they will be created.

Arguments

$controllerFileName  The path, file name, and extension of the INI file on the controller file system to open.

$section  The section in which the key is located. Specify an empty string if the key does not belong to a section.

$key  The key to which to write to the value.

$value  The value to assign to the key.

IMPORTANT: FileIniWriteValue() will make a new INI file if one does not exist. Make sure that the INI file name is correct. You can also use DirectoryFileExists() to determine if an INI file exists on your controller file system before you write a new value.

If you want to read to or write from a key that does not belong to a section, specify an empty string for that section.

Program Example

// Make a new key that does not belong to a section.
FileIniWriteValue("Example.ini", "", "Key1", "Value1")

// Read from the newly created key.
$sglobal[0] = FileIniReadValue("Example.ini", "", "Key1", "Key was not found.")

When you directly edit an INI file, you can put comment lines in the file. Comments must be standalone lines that start with a number sign (#) or a semicolon (;). Do not put a comment on the same line as a section or key-value pair. If you do this, the comment will be automatically removed the next time you use a FileIni function to do work with an INI file.

Example INI File

Copy
# Example.ini
#
# If the first non-whitespace line is a comment, the comment is viewed as
# an overview comment by File INI and will maintain two newlines
# between the end of this line and the next comment, section, or key.


; A key without a section. For keys without sections, specify
; them before sections.
;
; Notice that you can use a different comment character.
key1 = value1


; A non-nested section.
[section1]
key1 = value2


; A nested section.
[section1.nested1]
key1 = value3
key2 = 2

; You can have comments for keys too. File INI will try to maintain a 
; single newline to separate a comment from a key. In this case, a newline 
was automatically inserted to separate key2 from this comment.
; Note: This key and all others that follow without a section are still 
associated with section1.nested1.
key3 = 3.3
key4 = “444”

Program Example

// This program shows you the information that is read from the Example INI File: Example.ini.

// Shows value1
AppMessageDisplay(FileIniReadValue("Example.ini", "", "key1", "key1 was not found!"))

// Shows value2
AppMessageDisplay(FileIniReadValue("Example.ini", "section1", "key1", "section1 key1 was not found!"))

// Shows value3
AppMessageDisplay(FileIniReadValue("Example.ini", "section1.nested1", "key1", "section1.nested1 key1 was not found!"))

// Shows 2
AppMessageDisplay(FileIniReadValue("Example.ini", "section1.nested1", "key2", "section1.nested1 key2 was not found!"))

// Shows 3.3
AppMessageDisplay(FileIniReadValue("Example.ini", "section1.nested1", "key3", "section1.nested1 key3 was not found!"))

// Shows 444
AppMessageDisplay(FileIniReadValue("Example.ini", "section1.nested1", "key4", "section1.nested1 key4 was not found!"))

For more information about how to use FileIni functions, see the INI Files Example Program.

For information about how to edit INI files in the Programming module of the Develop workspace, see Working with INI Files.

Related Topics 

Controller File System

Files Example Program

INI Files Example Program