Q(uick)BASIC Function: FILEATTR

Quick View

FILEATTR

A file I/O function that returns information about an open file

Worth knowing

Useful and cross-version information about the programming environments of QBasic and QuickBasic.

Syntax
  • FILEATTR(filenumber%,attribute%)
Description/Parameter(s)
filenumber% The number of an open file.
attribute% Specifies the type of information to return. When attribute% is 1, FILEATTR returns a value indicating the file's access mode:
ValueMode
1Input
2Output
4Random
8Append
32Binary
When attribute% is 2, FILEATTR returns the DOS file handle.
Example
OPEN "TEST.DAT" FOR BINARY AS #1 PRINT FILEATTR(1, 1) CLOSE

See also:

Syntax
  • FILEATTR(filenumber,attribute)
Description/Parameter(s)
Argument Description
filenumber The number of an open file. This is the same number used in the OPEN statement. You can use a numeric expression as long as it evaluates to the number of an open file.
attribute Indicates the type of information to return. When attribute is 1, FILEATTR returns a code indicating a file's mode (see below). When attribute is 2, FILEATTR returns the file's DOS file handle.

The table below lists the return values and corresponding file modes when the value of attribute is 1.

Return Value Mode
1 INPUT
2 OUTPUT
4 RANDOM
8 APPEND
32 BINARY
Example

The following example opens two files and prints out the DOS file handles and modes returned by FILEATTR:

OPEN "tempfile.dat" FOR APPEND AS #1 OPEN "tempfl2.dat" FOR RANDOM AS #2 PRINT "Number Handle Mode" PRINT TAB(2);1;TAB(10);FILEATTR(1,2);TAB(15);FILEATTR(1,1) PRINT TAB(2);2;TAB(10);FILEATTR(2,2);TAB(15);FILEATTR(2,1) END

Sample Output:

Number Handle Mode 1 5 8 2 6 4

See also:

Syntax
  • FILEATTR(filenumber%,attribute%)
Description/Parameter(s)
  • The argument filenumber% is the number used in the OPEN statement to open the file or ISAM table. You can use a numeric expression as long as BASIC evaluates it to the number of an open file, device, or table.
  • The arguments attribute% and value& are described as follows:
Returns
When attribute% = 2 The DOS file handle if filenumber% indicates a file, or 0 if filenumber% indicates an ISAM table.
When attribute% = 1 A value indicating the file's mode:
ValueMode
1INPUT
2OUTPUT
4RANDOM
ValueMode
8APPEND
32BINARY
64ISAM
Example

This example uses the FILEATTR function to get the handles and modes from two opened files using the PRINT statement to print out the DOS file.

OPEN "tempfile.dat" FOR APPEND AS #1 OPEN "tempfl2.dat" FOR RANDOM AS #2 PRINT "Number Handle Mode" PRINT TAB(2); 1; TAB(10); FILEATTR(1, 2); TAB(15); FILEATTR(1, 1) PRINT TAB(2); 2; TAB(10); FILEATTR(2, 2); TAB(15); FILEATTR(2, 1) END

Sample Output:

Number Handle Mode 1 5 8 2 6 4