Int 21H [2.0] Function 43H (67) Get or set file attributes

Obtains or alters the attributes of a file (read-only, hidden, system, or archive) or directory.

Call with:

AH = 43H

AL = 00H to get attributes

01H to set attributes

CX = file attribute, if AL = 01H (bits can be combined)

Bit(s) Significance (if set)

0 read-only

1 hidden

2 system

3—4 reserved (0)

5 archive

6—15 reserved (0)

DS:DX = segment:offset of ASCIIZ pathname

Returns:

If function successful

Carry flag = clear

CX = file attribute

Bit(s) Significance (if set)

0 read-only

1 hidden

2 system

3 volume label

4 directory

5 archive

6—15 reserved (0)

If function unsuccessful

Carry flag = set

AX = error code

Notes:

Bits 3 and 4 of register CX must always be clear (0) when this function is called; in other words, you cannot change an existing file into a directory or volume label. However, you can assign the "hidden" attribute to an existing directory with this function.

[3.0+] If the program is running on a network, the user must have Create access rights to the directory containing the file whose attribute is to be modified.

Example:

Change the attribute of the file D:\MYDIR\MYFILE.DAT to read-only, so that it cannot be accidentally modified or deleted by other application programs.

rdonly equ 01h ; file attributes

hidden equ 02h

system equ 04h

volume equ 08h

subdir equ 10h

archive equ 20h

fname db 'D:\MYDIR\MYFILE.DAT',0

.

.

.

mov ah,43h ; function number

mov al,01h ; subfunction = modify

mov cx,rdonly ; read-only attribute

mov dx,seg fname ; filename address

mov ds,dx

mov dx,offset fname

int 21h ; transfer to MS-DOS

jc error ; jump if modify failed

.

.

.