Modifier

Partager via


File.Trunc() Method

Version: Available or changed with runtime version 1.0.

Truncate an ASCII or binary file to the current position of the file pointer.

Note

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

Syntax

 File.Trunc()

Note

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

Parameters

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

Remarks

Typically, you use this method together with Seek Method (File). Use File.Seek to position the pointer in the file and then use File.Trunc to truncate the file at that point.

Example

The following example sets a pointer at position 20 in a file and truncates the file at the pointer position. The WriteMode Method (File) allows the file that is named C:\TestFolder\TestFile.txt to open in write mode. The Seek method sets a pointer at position 20 in the file and then the Trunc Method (File) truncates the contents at the pointer position. This example assumes that you have created a text file named C:\TestFolder\TestFile.txt. The file is then saved a truncated file.

 var
    TestFile: File;
begin
    TestFile.WriteMode(True);  
    TestFile.Open('C:\TestFolder\TestFile.txt');  
    TestFile.Seek(20);  
    TestFile.Trunc;  
end;
  

File Data Type
Get Started with AL
Developing Extensions