mov cx, Attributes ;file attributes
mov dx, seg TempPath
mov ds, dx
mov dx, offset TempPath ;ds:dx points to directory path
mov ah, 5Ah ;Create Temporary File
int 21h
jc error_handler ;carry set means error
mov Handle, ax ;handle of temporary file
Create Temporary File (Function 5Ah) creates a file with a unique name and returns both a handle for the file and the new filename.
Attributes
Specifies the attributes to assign to the new file. This parameter can be some combination of the following attributes:
Value | Meaning |
ATTR_NORMAL (0000h) | File can be read from or written to. |
ATTR_READONLY (0001h) | File can be read from but not written to. |
ATTR_HIDDEN (0002h) | File does not appear in a directory listing. |
ATTR_SYSTEM (0004h) | File is a system file. |
ATTR_ARCHIVE (0020h) | File is marked for archiving. |
TempPath
Points to a zero-terminated ASCII string that specifies the path for the temporary file. TempPath must end with a backslash character (\) and a zero byte. The program must reserve the 13 bytes immediately following the terminating zero to hold the temporary filename.
If the function is successful, the carry flag is clear, the AX register contains a handle for the temporary file, and the 13-byte buffer following TempPath is filled in with the name of the temporary file. Otherwise, the carry flag is set and the AX register contains an error value, which may be one of the following:
Value | Name |
0003h | ERROR_PATH_NOT_FOUND |
0004h | ERROR_TOO_MANY_OPEN_FILES |
0005h | ERROR_ACCESS_DENIED |
When MS-DOS creates a file, it opens the file with read-and-write access and compatibility sharing mode and sets the file pointer to zero. If ATTR_READONLY is specified, the attribute takes effect only after the new file is closed.
If the specified file is on a network drive, the function creates the file only if network grants create access to the drive or directory.
MS-DOS does not delete temporary files; programs using temporary files should delete them when they are no longer in use.
Function 3Ch Create File with Handle
Function 5Bh Create New File