Truncate file

Command group Flag affected Reversible Execute on client Platform(s)
External commands YES NO NO Windows,Linux


Truncate file (refnum [,end-position] [,end-position-is-character]) Returns err-code


Note: The flag is set according to whether Omnis was able to make a call to this external command.

This command truncates a file. You specify the file reference number returned by Open file in refnum. The file is truncated at the current position of the file pointer or the specified end-position if given. The end-position parameter represents a byte position, unless you pass end-position-is-character as a non-zero value, in which case it represents an operating system character position (a byte position when running on Linux, or a 16-bit character position when running on Win32 or macOS).

It returns an error code (See Error Codes), or zero if no error occurs.


; write the contents of the character variable 'lCharVar' to a text file named 'charfile.txt' in the root of the omnis tree and then truncate the contents to 8 bytes sys(115) returns the full path to the Omnis executable
Calculate lPathname as con(sys(115),'charfile.txt')
Create file (lPathname) Returns lErrCode
Open file (lPathname,lRefNum)
Calculate lCharVar as 'Truncate the contents of this file'
Write file as character (lRefNum,lCharVar) Returns lErrCode
Truncate file (lRefNum,8) Returns lErrCode
Close file (lRefNum)