Creates a file with a unique name, in the current or specified directory on the default or specified disk drive, and returns a handle that can be used by the program for subsequent access to the file. The name generated for the file is also returned in a buffer specified by the program.
Call with:
AH = 5AH
CX = attribute (bits may 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 path
Returns:
If function successful
Carry flag = clear
AX = handle
DS:DX = segment:offset of complete ASCIIZ pathname
If function unsuccessful
Carry flag = set
AX = error code
Notes:
The ASCIIZ path supplied to this function should be followed by at least 13 additional bytes of buffer space. MS-DOS adds a backslash (\) to the supplied path, if necessary, then appends a null-terminated filename that is a function of the current time.
Files created with this function are not automatically deleted when the calling program terminates.
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.
See also Int 21H Functions 3CH, 5BH, and 6CH, which provide additional facilities for creating files.
[3.0+] If the program is running on a network, the file is created and opened for read/write access in compatibility sharing mode.
Example:
Create a temporary file with a unique name and normal attribute in directory \TEMP of drive C. Note that you must allow room for MS-DOS to append the generated filename to the supplied path. The complete file specification should be used to delete the temporary file before your program terminates.
fname db 'C:\TEMP\' ; pathname for temp file
db 13 dup (0) ; receives filename
fhandle dw ? ; file handle
.
.
.
mov ah,5ah ; function number
mov cx,0 ; 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
.
.
.