Sets the attributes of the file or directory, using system call 0x43.
#include <dos.h>
unsigned _dos_setfileattr( char *pathname, unsignedattrib );
pathname | Full path of target file/directory | |
attrib | New attributes |
The _dos_setfileattr routine uses system call 0x43 to set the attributes of the file or directory pointed to by pathname. The actual attributes are contained in 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 to without restriction. |
_A_RDONLY | Read-only. File cannot be opened for writing, 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. |
The function returns 0 if successful. Otherwise, it returns the DOS error code and sets errno to one of the following:
Constant | Meaning |
EACCES | Access denied; cannot change the volume ID or the subdirectory. |
ENOENT | No file or directory matching the target was found. |
Standards:None
16-Bit:DOS, QWIN, WIN, WIN DLL
32-Bit:None
/* 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 );
}
Attribute: 0x0020
Not a read only file.
Attribute: 0x0001
Attribute: 0x0020