MoveFileEx function

The MoveFileEx function moves a file from source to destination. Pointers to path strings are passed through the stack. The function automatically aligns the stack to 4 bytes.

Parameters (stack): 1. Pointer to the source file name. 2. Pointer to the destination path.

Return value: On success (CF=0) the file is moved; 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 MoveFileEx function to move a file from source to destination. Paths are passed through the stack.

title Author: Evgeny Sergeevich Dovgopolov

.286C
.model small
.stack 100h

data segment public
    path  db "folder\my_file\", 0
    fname db "test.txt", 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:[path]       ; Push the address of variable path onto the stack
        pushs   ds:[fname]      ; Push the address of variable fname onto the stack
        call    MoveFileEx      ; Call procedure MoveFileEx(fname, path) := CF

        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 function only modifies flags; no output is provided)

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