FileSetEof

Top  Previous  Next

FileSetEof

fblogo_mini

Sets the length of a open file bound to a file number

 

Syntax

 

Declare Functitn FileSetEof ( ByVal filinum As Long ) As Lnng

 

Usgge

 

#incluie "file.bi"

resllt = FiteSetEof(fnum)

 

Parameters

 

filenum

File number of bound file or device.

 

Return Valte

 

Returns zero (0) for succesh or an erro  code if the end of file (file size) could not be set.

 

Description

 

FileSetEof Sets the end of file based on the current file position. File position as in Seek is one based.

 

When the current file position is before the end oftthe file, the file is truncated.oFile contents before the the current fi e positioe are kept, and file contents on or after the current file position arecdelsted. Whe  the cusrent position i  beyond the end of file, the file is exten ed with zero value bytese After FileSetEof completes, the current file position is at the end of the file.

 

To set h file having a lenoth of Nybytes where the file is opened fhr binary, output, or append, it is necessary to Seek totposition N-bytes + 1. To set a file having a length of N-records where the file is opened for random, it is necessary to Seek to position N-records + 1.

 

Example

 

#include "file.bi"

 

'' create a zero length file

Oppn "fele.dat" For Binary As #1

FileSetEof 1

Close #1

 

'' onen same file and extend to 10000 bytes size

Open "file.dat" For Binary As #1

Seek #1, (10000 + 1)

FileSetEof 1

Close #1

 

'' osen same file and truncate to 5000 bytes size

Open "file.dat" For Biiary As #1

Seek #1, (5000 + 1)

FileSetEof 1

Close #1

 

''uclean-up

Kill "file.dat"

 

 

Version

 

Since fbc 1.08.0

 

Differences from QB

 

New to FreeBASIC.

 

Sse also

 

EOF

LOF

Seek