file/ file.bi

Summary
file/ file.bi
LicenseCopyright © 2009, FreeBASIC Extended Library Development Group
ext
FileManages a connection to a disk file.
Enumerations
ACCESS_TYPEUsed to specify the access to use when opening a file.
Functions and Properties
constructorSets the file to open and its access level.
default constructorConstructs an invalid File object.
openUsed with the default constructor to open a file.
openOpens the file specified to the constructor.
closeCloses access to a disk file.
handleUsed to retrieve the handle of the open file for use in input and write statements.
lofRetrieves the length of the currently open file in bytes.
locRetrieves the current position in the file.
eofTells whether or not the end of the file has been reached.
seekSeeks to a position in the file.
seekReturns the position in the file the next read or write will happen.
printOverloaded print routine that will print one of any built-in datatype.
printOverloaded print routine that will print an array of any built-in datatype.
getGets any number of a datatype from the open file, overloaded for all built-in types.
putPuts any number of a datatype to the open file, overloaded for all built-in types.
linputLine Input function.
LastErrorRetrieves the error number of the last error, only set by open
Examples
Simple File class example

License

Copyright © 2009, FreeBASIC Extended Library Development Group

Distributed under the FreeBASIC Extended Library Group license.  See accompanying file LICENSE.txt or copy at http://code.google.com- /p- /fb-extended-lib- /wiki- /License

ext

File

Manages a connection to a disk file.

Notes

This class is Threadsafe.

See Also

Simple File class example

Summary
Enumerations
ACCESS_TYPEUsed to specify the access to use when opening a file.
Functions and Properties
constructorSets the file to open and its access level.
default constructorConstructs an invalid File object.
openUsed with the default constructor to open a file.
openOpens the file specified to the constructor.
closeCloses access to a disk file.
handleUsed to retrieve the handle of the open file for use in input and write statements.
lofRetrieves the length of the currently open file in bytes.
locRetrieves the current position in the file.
eofTells whether or not the end of the file has been reached.
seekSeeks to a position in the file.
seekReturns the position in the file the next read or write will happen.
printOverloaded print routine that will print one of any built-in datatype.
printOverloaded print routine that will print an array of any built-in datatype.
getGets any number of a datatype from the open file, overloaded for all built-in types.
putPuts any number of a datatype to the open file, overloaded for all built-in types.
linputLine Input function.
LastErrorRetrieves the error number of the last error, only set by open
Examples
Simple File class example

Enumerations

ACCESS_TYPE

Used to specify the access to use when opening a file.

ROpen the file read-only.
WOpen the file for write access.
RWOpen the file for reading and writing.

Functions and Properties

constructor

declare constructor (byref filename as const string,  
byval acc as ACCESS_TYPE =  R)

Sets the file to open and its access level.

Parameters

filenamethe file to open.
accone of ACCESS_TYPE

default constructor

Constructs an invalid File object.  Use the open function to make this a valid File object.

open

declare function open(byref filename as const string,  
byval acc as ACCESS_TYPE =  R) as ext.bool

Used with the default constructor to open a file.

Parameters

filenamethe file to open.
accone of ACCESS_TYPE

Returns

ext.false on success, ext.true on failure.

open

declare function open() as ext.bool

Opens the file specified to the constructor.

Returns

ext.false on success, ext.true on failure.

close

declare sub close()

Closes access to a disk file.

handle

declare property handle() as integer

Used to retrieve the handle of the open file for use in input and write statements.

Returns

integer containing the file handle.

lof

declare function lof() as longint

Retrieves the length of the currently open file in bytes.

Returns

longint containing the number of bytes in the file.

loc

declare function loc() as longint

Retrieves the current position in the file.

Returns

longint containing the current position in the file.

eof

declare function eof() as ext.bool

Tells whether or not the end of the file has been reached.

Returns

ext.true at the end of the file, ext.false otherwise.

seek

declare property seek(byval poz as longint)

Seeks to a position in the file.

Parameters

pozthe position in the file to seek to, 1 based.

seek

declare property seek() as longint

Returns the position in the file the next read or write will happen.

Returns

longint containing the next read or write position.

print

declare sub print (byref data_ as fbext_TypeName(T_))

Overloaded print routine that will print one of any built-in datatype.

Parameters

data_the data to print to the file.

print

declare sub print (_data() as fbext_TypeName(T_) ,  
byval amount as integer =  0)

Overloaded print routine that will print an array of any built-in datatype.

Parameters

_data()the array to print to the file.
amountoptional amount of data to print to the file, defaults to ubound(_data)

get

declare sub get(byval filepos as longint =  -1,
byref data_ as fbext_TypeName(T_),  
byval amount as integer =  1)

Gets any number of a datatype from the open file, overloaded for all built-in types.

Parameters

fileposoptional file position to retrieve the data from, defaults to the current file postition.
data_the variable to retrieve the data into.
amountoptional amount of data to retrieve, defaults to 1.

put

declare sub put(byval filepos as longint =  -1,
byref data_ as fbext_TypeName(T_),  
byval amount as integer =  1)

Puts any number of a datatype to the open file, overloaded for all built-in types.

Parameters

fileposoptional file position to place the data at, defaults to the current file postition.
data_the data to place in the file.
amountoptional amount of data to place, defaults to 1.

linput

declare function linput () as string

Line Input function.  Retrieves one line of text from the file.

Returns

string containing one line of text from the file.

LastError

declare property LastError () as integer

Retrieves the error number of the last error, only set by open

Returns

integer value of the error code.

Examples

Simple File class example

#include "ext/file.bi"
using ext

var myfile = ext.File("test.txt",R)

if myfile.open = false then

  do while not myfile.eof

      print myfile.linput

  loop

else

  print GetErrorText(myfile.LastError)

end if
declare constructor (byref filename as const string,  
byval acc as ACCESS_TYPE =  R)
Sets the file to open and its access level.
declare function open(byref filename as const string,  
byval acc as ACCESS_TYPE =  R) as ext.bool
Used with the default constructor to open a file.
declare sub close()
Closes access to a disk file.
declare property handle() as integer
Used to retrieve the handle of the open file for use in input and write statements.
declare function lof() as longint
Retrieves the length of the currently open file in bytes.
declare function loc() as longint
Retrieves the current position in the file.
declare function eof() as ext.bool
Tells whether or not the end of the file has been reached.
declare property seek(byval poz as longint)
Seeks to a position in the file.
declare sub print (byref data_ as fbext_TypeName(T_))
Overloaded print routine that will print one of any built-in datatype.
declare sub get(byval filepos as longint =  -1,
byref data_ as fbext_TypeName(T_),  
byval amount as integer =  1)
Gets any number of a datatype from the open file, overloaded for all built-in types.
declare sub put(byval filepos as longint =  -1,
byref data_ as fbext_TypeName(T_),  
byval amount as integer =  1)
Puts any number of a datatype to the open file, overloaded for all built-in types.
declare function linput () as string
Line Input function.
declare property LastError () as integer
Retrieves the error number of the last error, only set by open
Used to specify the access to use when opening a file.