RenameFolderEx function

The RenameFolderEx function renames a folder. Pointers to the old and new names are passed through the stack. The function automatically aligns the stack to 4 bytes.

Parameters (stack): 1. Pointer to the current name. 2. Pointer to the new name.

Return value: On success (CF=0) the folder is renamed; 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 RenameFolderEx function to rename a folder. The names are passed through the stack.

title Author: Evgeny Sergeevich Dovgopolov

.286C
.model small
.stack 100h

data segment public
    fOldName db "Assembly", 0
    fNewName db "Handyfar", 0
    rSuccess db "The folder was renamed successfully to '%s'.\0"
    rError   db "An error occurred while renaming '%s' to '%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   es:[fNewName]         ; 2nd: Push the address of variable fNewName onto the stack
        pushs   ds:[fOldName]         ; 1st: Push the address of variable fOldName onto the stack
        call    RenameFolderEx        ; Call procedure RenameFolderEx(fOldNam, fNewNam) := AX and CF

        jnc     @NoRenameFolderError  ; If CF=0, jump to label @NoRenameFolderError

        push    ax                    ; 4th: Push ax (error code) onto the stack
        pushs   ds:[fNewName]         ; 3rd: Push the address of variable fNewName onto the stack
        pushs   ds:[fOldName]         ; 2nd: Push the address of variable fOldName onto the stack
        leaax   ds:[rError]           ; 1st: Load the address of format string rError into register ds:ax
        call    PrintFormatString     ; Call procedure PrintFormatString(ax:rError, ...)
        add     sp, 6                 ; Align the stack
        jmp     @Done                 ; Perform an unconditional jump to label @Done

    @NoRenameFolderError:
        pushs   ds:[fNewName]         ; 2nd: Push the address of variable fNewName onto the stack
        leaax   ds:[rSuccess]         ; 1st: Load the address of format string rSuccess into register ds:ax
        call    PrintFormatString     ; Call procedure PrintFormatString(ax:rSuccess, fNewName)
        add     sp, 2                 ; Align the stack

    @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 renamed successfully to 'Handyfar'.

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