The DeleteFolder function

The DeleteFolder function deletes the folder with the specified name.

Parameters: AX: pointer to the string with 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

An example program for the Intel 8086 assembler demonstrating the use of the DeleteFolder function to delete a folder.

title Author: Evgeny Sergeevich Dovgopolov

.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                  ; 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    DeleteFolder         ; Call the DeleteFolder procedure (ax:fName) := AX and CF

        jnc     NoDeleteFolderError  ; If CF=0, jump to the NoDeleteFolderError 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:[dError]      ; 1st: Load the address of the dError format string into the ds:ax register
        call    PrintFormatString    ; Call the PrintFormatString procedure (ax:dError, fName)
        add     sp, 4                ; Align the stack
        jmp     Done                 ; Perform an unconditional jump to the Done label

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

    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 deleted successfully!

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