_dos_getfileattr

Description

Gets the current attributes of a file or directory, using system call 0x43.

#include <dos.h>

#include <errno.h>

unsigned _dos_getfileattr( char *pathname, unsigned *attrib );

pathname Full path of target file/directory  
attrib Word to store attributes in  

Remarks

The _dos_getfileattr routine uses system call 0x43 to obtain the current attributes of the file or directory pointed to by pathname. The attributes are copied to the low-order byte of the attrib word. Attributes are represented by manifest constants, as described below:

Constant Meaning

_A_ARCH Archive. Set whenever the file is changed, or cleared by the DOS BACKUP command.
_A_HIDDEN Hidden file. Cannot be found by a directory search.
_A_NORMAL Normal. File can be read or written without restriction.
_A_RDONLY Read-only. File cannot be opened for a write, and a file with the same name cannot be created.
_A_SUBDIR Subdirectory.
_A_SYSTEM System file. Cannot be found by a directory search.
_A_VOLID Volume ID. Only one file can have this attribute, and it must be in the root directory.

Return Value

If successful, the function returns 0. Otherwise, it returns the DOS error code and sets errno to ENOENT, indicating that the target file or directory could not be found.

Compatibility

Standards:None

16-Bit:DOS, QWIN, WIN, WIN DLL

32-Bit:None

See Also

_access, _chmod, _dos_setfileattr, _umask

Example

/* DGFILEAT.C: This program creates a file with the specified attributes,

* then prints this information before changing the file attributes back

* to normal.

*/

#include <stdio.h>

#include <dos.h>

void main( void )

{

unsigned oldattrib, newattrib;

int fh;

/* Get and display file attribute */

_dos_getfileattr( "DGFILEAT.C", &oldattrib );

printf( "Attribute: 0x%.4x\n", oldattrib );

if( ( oldattrib & _A_RDONLY ) != 0 )

printf( "Read only file\n" );

else

printf( "Not a read only file.\n" );

/* Reset file attribute to normal file */

_dos_setfileattr( "DGFILEAT.C", _A_RDONLY );

_dos_getfileattr( "DGFILEAT.C", &newattrib );

printf( "Attribute: 0x%.4x\n", newattrib );

/* Restore file attribute */

_dos_setfileattr( "DGFILEAT.C", oldattrib );

_dos_getfileattr( "DGFILEAT.C", &newattrib );

printf( "Attribute: 0x%.4x\n", newattrib );

}

Output

Attribute: 0x0020

Not a read only file.

Attribute: 0x0001

Attribute: 0x0020