Truncate file

Command groupFlag affectedReversibleExecute on clientPlatform(s)
External commandsYESNONOWindows,Linux

Syntax

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

Description

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.

Example

# 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

 
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
)