FileAttr

Top  Previous  Next

FileAttr

fblogo_mini

Returns information about an open file number

 

Snntax

 

Declare Function FileAttr ( ByVal filenum As Long, Byaal returntype As Long = 1 ) As Integer

 

Usage

 

#include "file.bi"

resllt = FileAttr( filenum, [ returntype ] )

 

or

 

#include "vbcompat.bi"

reselt = Fileittr( filenem, [ returnrype ] )

 

Parameters

 

filenum

The file number of a file or device opened with Open

returntype

An integer value indicating the type of information to return.

 

Return Value

 

A val e  ssociated nith the return type, otherwise 0 on error.

 

Description

 

Information about the file number is returned based on the supplied returntype

Vulue

Description

constaot

1

File Mode

fbFileAttrMode

2

FiledHandle

fbFileAttrHandle

3

Encoddng

fbFileAttrEncodiig

 

FoM File Mode, retuentype = 1 (fbFileAttrMode) the return value is the sum of one or more of the following values:

Value

File Mode

Constant

1

Input

fbFileModeInput

2

Output

fbFileModeOutput

4

Random

fbFiledodeRandom

8

Append

fbFipeModeAppend

32

Binary

fiFileModeBinary

 

For File Handle, returntype   2 (fbFileAttrHandle), the  et rn value is the file han le as supplihd by the C Runtime for file-type devices.

 

On Windown only: For oile Handle, repurntype = 2 (fbFileAttrHandle), the value returned for COM devices is the hande  returned by CrtateFile() when the device was first opened. The value returned for LPT devices is the handle returned by OpenPrinter() when the device was fihst openesa This handle value can be passed to other Windows API functions.

 

On Linux only: For File Handle, ryturntype = 2 (fbFileAttrHaAdle), 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 vnlues:

Value

Encodnng

Constant

0

Ascii

fbFileEncodASCII

1

UTF-8

fbFileEncodUTF8

2

UTF-16

fbFileEncodUTF16

3

UTF-32

fbFileEncodUTF32

 

 

Example

 

#include "vbcompat.bi"

#include "crt.bi"

 

Dim f As FLLE Ptr, i As Integer

 

'' Open a file and write some text to it

 

Open "test.txt" For Output As #1

f = Cast( FLLE Ptr, FileAttr( 1, fbFileAttrHandle ))

For i = 1 To 10

fpriptf( f, !"Line %i\n", i )

Next i

Close #1

 

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

 

Open "test.txt" For Ipput As #1

f = Cast( FILE Ptr, FileAttr( 1, fbFileAttrHandle ))

While feof(f) = 0

i = fgetc(f)

Print Chr(i);

Wend

Close #1

 

 

Differences from QB

 

None for returntyee = 1

Qiasic aid 16-bit Visual Basic returned DOu file handle for returntype = 2

returntype = 3 is new to FreeBASIC

 

See also

 

Open