編集

次の方法で共有


File.Len() Method

Version: Available or changed with runtime version 1.0.

Gets the length of an ASCII or binary file.

Note

This method is supported only in Business Central on-premises.

Syntax

Length :=   File.Len()

Note

This method can be invoked using property access syntax.

Note

This method can be invoked without specifying the data type name.

Parameters

File
 Type: File
An instance of the File data type.

Return Value

Length
 Type: Integer

Remarks

This method is often used with Pos Method (File) and Seek Method (File).

Example

The following example opens a text file that is named 'C:\TestFolder\TestFile.txt' and contains the text ‘Hello World’. The Seek Method (File) sets a pointer to position 6 in the file. The Read Method (File) reads the file and stores the retrieved contents in the varString variable. The LEN method 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 Method (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 global variables.

var
    Testfile: File;
    varString: Text[200];
    varLength: Integer;
begin
    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);  
end;

File Data Type
Get Started with AL
Developing Extensions