The RenameFolder function

The RenameFolder function renames a folder.

Parameters: DS:AX - pointer to the string with the current folder name; ES:BX - pointer to the string with the new folder 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

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

title Author: Evgeny Sergeevich Dovgopolov

.model small
.stack 100h

data segment public
    fOldName db "Assembly", 0
    fNewName db "Handyfar", 0
    rSuccess db "The folder was successfully renamed to '%s'.\0"
    rError   db "An error occurred while renaming '%s' to '%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     bx, es:[fNewName]    ; 2nd: Load the address of the string fNewName into the es:bx register
        lea     ax, ds:[fOldName]    ; 1st: Load the address of the string fOldName into the ds:ax register
        call    RenameFolder         ; Call the RenameFolder procedure (ds:ax, es:bx) := AX and CF

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

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

    NoRenameFolderError:
        lea     ax, ds:[fNewName]    ; Load the address of the variable fNewName into the ds:ax register
        push    ax                   ; 2nd: save the ax register value on the stack
        lea     ax, ds:[rSuccess]    ; 1st: Load the address of the format string rSuccess into the ds:ax register
        call    PrintFormatString    ; Call the PrintFormatString procedure (ax:rSuccess, fNewName)
        add     sp, 2                ; Align the stack

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

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