mov dx, seg FileName
mov ds, dx
mov dx, offset FileName ;ds:dx points to new filename
mov cx, Attributes ;file attributes
mov ah, 5Bh ;Create New File
int 21h
jc error_handler ;carry set means error
mov Handle, ax ;handle of file
Create New File (Function 5Bh) creates a file and assigns it the first available handle. If the specified file already exists, this function fails.
FileName
Points to a zero-terminated ASCII string that specifies the new filename. The name must be a valid MS-DOS filename and cannot contain wildcards.
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. |
If the function is successful, the carry flag is clear and the AX register contains the new file handle. 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 |
0050h | ERROR_FILE_EXISTS |
Create New File returns 0050h (ERROR_FILE_EXISTS) if a file with the specified name already exists.
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.
Function 3Ch Create File with Handle
Function 4300h Get File Attributes
Function 4301h Set File Attributes
Function 5Ah Create Temporary File