Wiki source for KeyPgFileattr


Show raw source

{{fbdoc item="title" value="FILEATTR"}}----
Returns information about an open file number

{{fbdoc item="syntax"}}##
[[KeyPgDeclare|declare]] [[KeyPgFunction|function]] **""FileAttr""** ( [[KeyPgByval|byval]] //filenum// [[KeyPgAs|as]] [[KeyPgLong|long]], [[KeyPgByval|byval]] //returntype// [[KeyPgAs|as]] [[KeyPgLong|long]] = 1 ) [[KeyPgAs|as]] [[KeyPgInteger|integer]]
##
{{fbdoc item="usage"}}##
#include "file.bi"
//result// = **""FileAttr""**( //filenum//, [ //returntype// ] )
##
//or//
##
#include "vbcompat.bi"
//result// = **""FileAttr""**( //filenum//, [ //returntype// ] )
##
{{fbdoc item="param"}}
##//filenum//##
The file number of a file or device opened with ##[[KeyPgOpen|Open]]##
##//returntype//##
An integer value indicating the type of information to return.

{{fbdoc item="ret"}}
A value associated with the return type, otherwise 0 on error.

{{fbdoc item="desc"}}
Information about the file number is returned based on the supplied ##//returntype//##
{{table columns="3" cellpadding="1" cells="Value;Description;constant;1;File Mode;fbFileAttrMode;2;File Handle;fbFileAttrHandle;3;Encoding;fbFileAttrEncoding"}}

For File Mode, ##//returntype//## = 1 (##fbFileAttrMode##) the return value is the sum of one or more of the following values:
{{table columns="3" cellpadding="1" cells="Value;File Mode;Constant;1;Input;fbFileModeInput;2;Output;fbFileModeOutput;4;Random;fbFileModeRandom;8;Append;fbFileModeAppend;32;Binary;fbFileModeBinary"}}

For File Handle, ##//returntype//## = 2 (##fbFileAttrHandle##), the return value is the file handle as supplied by the C Runtime for file-type devices.

On Windows only: For File Handle, ##//returntype//## = 2 (##fbFileAttrHandle##), the value returned for COM devices is the handle returned by ##""CreateFile""()## when the device was first opened. The value returned for LPT devices is the handle returned by ##""OpenPrinter""()## when the device was first opened. This handle value can be passed to other Windows API functions.

On Linux only: For File Handle, ##//returntype//## = 2 (##fbFileAttrHandle##), the value returned for COM devices is the file descriptor returned by open() when the device was first opened.

For Encoding, ##//returntype//## = 3 (##fbFileAttrEncoding##), the return value is one of the following values:
{{table columns="3" cellpadding="1" cells="Value;Encoding;Constant;0;Ascii;fbFileEncodASCII;1;UTF-8;fbFileEncodUTF8;2;UTF-16;fbFileEncodUTF16;3;UTF-32;fbFileEncodUTF32"}}

{{fbdoc item="ex"}}
{{fbdoc item="filename" value="examples/manual/system/fileattr.bas"}}%%(freebasic)
#include "vbcompat.bi"
#include "crt.bi"

dim f as FILE ptr, i as integer

'' Open a file and write some text to it

open "test.txt" for output as #1
f = cast( FILE ptr, FileAttr( 1, fbFileAttrHandle ))
for i = 1 to 10
fprintf( f, !"Line %i\n", i )
next i
close #1

'' re-open the file and read the text back

open "test.txt" for input as #1
f = cast( FILE ptr, FileAttr( 1, fbFileAttrHandle ))
while feof(f) = 0
i = fgetc(f)
print chr(i);
wend
close #1
%%

{{fbdoc item="diff"}}
- None for ##//returntype//## = 1
- QBasic and 16-bit Visual Basic returned DOS file handle for ##//returntype//## = 2
- ##//returntype//## = 3 is new to ""FreeBASIC""

{{fbdoc item="see"}}
- ##[[KeyPgOpen|Open]]##

{{fbdoc item="back" value="CatPgOpsys|Operating System Functions"}}
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki



sf.net phatcode