DeleteFolderEx function

The DeleteFolderEx function deletes an empty folder. The pointer to the folder name is passed through the stack. The function automatically aligns the stack to 2 bytes.

Parameters (stack): 1. Pointer to the folder name.

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

Flag state: The function affects all flags.

Program source code

Intel 8086 assembly program example demonstrating the use of the DeleteFolderEx function to delete an empty folder. The folder name is passed through the stack.

title Author: Evgeny Sergeevich Dovgopolov

.286C
.model small
.stack 100h

data segment public
    fName    db "Assembly", 0
    dSuccess db "The folder was deleted successfully!\0"
    dError   db "An error occurred while deleting '%s'. Error code: %d\0"
data ends

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

    main proc
        call    SetDataSegment        ; Call the SetDataSegment procedure

        pushs   ds:[fName]            ; Push the address of the fName variable onto the top of the stack
        call    DeleteFolderEx        ; Call the DeleteFolderEx(fName) procedure := AX and CF

        jnc     @NoDeleteFolderError  ; If CF=0, jump to the label @NoDeleteFolderError

        push    ax                    ; 3rd: Push ax onto the top of the stack (error code)
        pushs   ds:[fName]            ; 2nd: Push the address of the fName variable onto the top of the stack
        leaax   ds:[dError]           ; 1st: Load the address of the dError format string into the ds:ax register
        call    PrintFormatString     ; Call the PrintFormatString(ax:dError, fName, ax) procedure
        add     sp, 4                 ; Align the stack
        jmp     @Done                 ; Jump unconditionally to the label @Done

    @NoDeleteFolderError:
        pushs   ds:[dSuccess]         ; Push the address of the dSuccess variable onto the top of the stack
        call    WriteStringEx         ; Call the WriteStringEx(dSuccess) procedure

    @Done:
        push    0                     ; Push the byte return code onto the top of the stack
        call    ExitProcessEx         ; Call the ExitProcessEx(0) procedure
    main endp

code ends
end main

The folder was deleted successfully!

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