Int 21H [2.0] Function 3CH (60) Create file

Given an ASCIIZ pathname, creates a new file in the designated or default directory on the designated or default disk drive. If the specified file already exists, it is truncated to zero length. In either case, the file is opened and a handle is returned that can be used by the program for subsequent access to the file.

Call with:

AH = 3CH

CX = file attribute (bits may be combined)

Bit(s) Significance (if set)

0 read-only

1 hidden

2 system

3 volume label

4 reserved (0)

5 archive

6—15 reserved (0)

DS:DX = segment:offset of ASCIIZ pathname

Returns:

If function successful

Carry flag = clear

AX = handle

If function failed

Carry flag = set

AX = error code

Notes:

The function fails if:

any element of the pathname does not exist.

the file is being created in the root directory and the root directory is full.

a file with the same name and the read-only attribute already exists in the specified directory.

[3.0+] the program is running on a network and the user running the program has insufficient access rights.

A file is usually given a normal (0) attribute when it is created. The file's attribute can subsequently be modified with Int 21H Function 43H.

[3.0+] A volume label can be created using an attribute of 0008H, if one does not already exist. When files are created, bit 3 of the attribute parameter should always be clear (0).

[3.0+] See the entries for Int 21H Functions 5AH and 5BH, which may also be used to create files.

[4.0+] Int 21H Function 6CH combines the services of Functions 3CH, 3DH, and 5BH.

Example:

Create and open, or truncate to zero length and open, the file C:\MYDIR\MYFILE.DAT, and save the handle for subsequent access to the file.

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

fhandle dw ?

.

.

.

mov ah,3ch ; function number

xor cx,cx ; normal attribute

mov dx,seg fname ; address of pathname

mov ds,dx

mov dx,offset fname

int 21h ; transfer to MS-DOS

jc error ; jump if create failed

mov fhandle,ax ; save file handle

.

.

.