Share via


LEN Function (File)

Gets the length of an ASCII or binary file.

Length := File.LEN

Parameters

  • File
    Type: File Use this variable to refer to the file.

Property Value/Return Value

Type: Integer

The length of the file in bytes.

Remarks

This function is often used with POS Function (File) and SEEK Function (File).

Example

The following example opens a text file that is named 'C:\TestFolder\TestFile.txt' and contains the text ‘Hello World’. The SEEK Function (File) sets a pointer to position 6 in the file. The READ Function (File) reads the file and stores the retrieved contents in the varString variable. The LEN function retrieves the length of the file and stores it the varLength variable. The text that is read starts from the position of the pointer, so the text ‘World’ and the length of 12 are displayed in the message box. The length of the file is not affected by the SEEK Function (File). This example assumes that you have created the text file that is named C:\TestFolder\TestFile.txt and contains the text ‘Hello World’. This example requires that you create the following variables in the C/AL Globals window.

Variable name DataType Length

Testfile

File

Not applicable

varString

Text

200

varLength

Integer

Not applicable

Testfile.OPEN('C:\TestFolder\TestFile.txt');
Testfile.SEEK(6);
Testfile.READ(varString);
varLength := Testfile.LEN;
MESSAGE('The text is: %1. The length of the file is: %2', varString, varLength);

See Also

Reference

File Data Type