Borland C++ reference

_dos_getfileattr, _dos_setfileattr

raw OCR

Changes file access mode.

Defined in header <dos.h>

Syntax

#include <dos.h>
int _dos_getfileattr(const char *path, unsigned *attribp);
int _dos_setfileattr(const char path, unsigned attrib);

Portability

DOSUNIXWindowsANSI CC++ only
■■

Remarks

_dos_getfileattr fetches the DOS file attributes for the file path. The attributes are stored at the location pointed to by attribp.

_dos_setfileattr sets the DOS file attributes for the file path to the value attrib.

The DOS file attributes can be a OR combination of the following symbolic constants (defined in dos.h):

_A_RDONLYRead-only attribute
_A_HIDDENHidden file
_A_SYSTEMSystem file
_A_VOLIDVolume label
_A_SUBDIRDirectory
_A_ARCHArchive
_A_NORMALNormal file (no attribute bits set)

Return value

Upon successful completion, _dos_getfileattr and _dos_setfileattr return 0. Otherwise, these functions return the DOS error code, and the global variable errno is set to the following: ENOENT Path or file name not found

See also

Example

#include <stdio.h>
#include <dos.h>

int main (void)
char filename [128];
unsigned attrib;

printf( "Enter a file name:");
scanf("%s",  filename);
if  (_dos_getfileattr(filename,&attrib)  != 0) {
   perror ("Unable to obtain file attributes");
   return 1;
}
if  (attrib & _A_RDONLY) {
   printf("%s  currently read-only, making it read-write. \n", filename);
   attrib &= ~_A_RDONLY;
}
else (
   printf("%s currently  read-write, making it read-only. \n", filename);
   attrib  1= _A_RDONLY;
}
if (_dos_setfileattr (filename,attrib) != 0)
   perror ("Unable to set file attributes");
return 0;

Differences from modern implementations

Nothing recorded yet.

Modern references

These are search links, not yet checked by hand.

Extraction notes

  • heading `dos_getfileattr, _clos_setfileattr` read as `_dos_getfileattr, _dos_setfileattr`