Repository navigation
Fileseteof
Home › Operating System Functions › FileSetEof
Cuts or extends an open file so that it ends at the current position.
Declare Function FileSetEof ( ByVal filenum As Long ) As Longfilenum
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 of the file, the file is truncated. File contents before the the current file position are kept, and file contents on or after the current file position are deleted. When the current position is beyond the end of file, the file is extended with zero value bytes. After FileSetEof completes, the current file position is at the end of the file.
To set a file having a length of N-bytes where the file is opened for binary, output, or append, it is necessary to Seek to position 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.
Returns zero (0) for success or an error code if the end of file (file size) could not be set.
#include "file.bi"
result = FileSetEof(fnum)- New to FreeBASIC.
#include "file.bi"
'' create a zero length file
Open "file.dat" For Binary As #1
FileSetEof 1
Close #1
'' open same file and extend to 10000 bytes size
Open "file.dat" For Binary As #1
Seek #1, (10000 + 1)
FileSetEof 1
Close #1
'' open same file and truncate to 5000 bytes size
Open "file.dat" For Binary As #1
Seek #1, (5000 + 1)
FileSetEof 1
Close #1
'' clean-up
Kill "file.dat"Category: Operating System Functions
Kind: function
Reproduced from the FreeBASIC Wiki Manual under the GNU Free Documentation License 1.3 — with no Invariant Sections, no Front-Cover Texts and no Back-Cover Texts. Copyright © the FreeBASIC project and wiki contributors. See License.
tiko-lang · Home · Feature Index · Keyword Index · License
FreeBASIC manual pages reproduced under the GNU FDL 1.3.
- Generics
- Interfaces
- For Each
- Iterators
- Tuples
- Array Results
- Defer
- Lambdas
- Block Strings
- Partial Types
- String Slices
- Embed
- Typed Variadics
- C Header Import
- Foreign Library Linking
- UString
- Fixed-Width Types
- Nullptr
- String Library
- Format
- Array
- Map
- Set
- LinkedList
- OrderedMap
- OrderedSet
- Sorting
- Optional
- Result
- Smart Pointers
- Date and Time (Chrono)
- Filesystem
- File Streams
- Config (INI and TOML)
- Codec
- Hash
- UUID
- OS
- Process
- Net
- HTTP and TLS
- Math Library
- Finance
- Logging
- Terminal TUI Library
- PsControls
- tkControls
- sys/win
- Goroutines and Channels
- LLVM Backend
- tiko build
- TIKO_COMPILER
- Variable Declarations
- Standard Data Types
- User Defined Types
- Procedures
- Operators
- Control Flow Statements
- Converting Data Types
- Array Functions
- String Functions
- Mathematical Functions
- Bit Manipulation
- Date and Time Functions
- File I/O Functions
- Console Functions
- User Input (Runtime Library)
- User Input Functions (Graphics Library)
- Screen Functions
- 2D Drawing Functions
- Graphics Library Reference
- Graphics Keyword List
- Memory Functions
- Threading Support Functions
- Error Handling Functions
- Operating System Functions
- Preprocessor
- Intrinsic Defines
- Miscellaneous Keywords
- Modularizing