The CreateFolder function

The CreateFolder function creates a folder with the specified name.

Parameters: AX: pointer to the string with the folder name.

Return value: On success (CF=0) the folder is created; on error (CF=1) AX contains the error code.

Flag state: The function affects all flags.

Program source code

An example program for the Intel 8086 assembler demonstrating the use of the CreateFolder function to create a new folder.

title Author: Evgeny Sergeevich Dovgopolov

.model small
.stack 100h

data segment public
    fName    db "Assembly", 0
    cSuccess db "The folder was created successfully!\0"
    cError   db "An error occurred while creating '%s'. Error code: %d\0"
data ends

code segment public                  ; Start of the code segment
    assume  ds:data, cs:code
    include Handyfar.inc             ; Include the file with functions

    main proc                        ; Start of the main procedure
        call    SetDataSegment       ; Call the SetDataSegment procedure

        lea     ax, ds:[fName]       ; Load the address of the string fName into the ds:ax register
        call    CreateFolder         ; Call the CreateFolder procedure (ax:fName) := AX and CF

        jnc     NoCreateFolderError  ; If CF=0, jump to the NoCreateFolderError label

        push    ax                   ; 3rd: Save the ax register value on the stack
        lea     ax, ds:[fName]       ; Load the address of the variable fName into the ds:ax register
        push    ax                   ; 2nd: save the ax register value on the stack
        lea     ax, ds:[cError]      ; 1st: Load the cError format string into the ds:ax register
        call    PrintFormatString    ; Call the PrintFormatString procedure (ax:cError, fName)
        add     sp, 4                ; Align the stack
        jmp     Done                 ; Perform an unconditional jump to the Done label

    NoCreateFolderError:
        lea     ax, ds:[cSuccess]    ; Load the address of the string cSuccess into the ds:ax register
        call    WriteString          ; Call the WriteString procedure (ax:cSuccess)

    Done:
        xor     al, al               ; Clear the al register
        call    ExitProcess          ; Call the ExitProcess procedure
    main endp                        ; End of the main procedure

code ends                            ; End of the code segment
end main	                         ; End of file. The main procedure is the entry point

The folder was created successfully!

Example taken from the textbook "HANDYFAR - MASM (Evgeny Sergeevich Dovgopolov)".