The CopyFile function

The CopyFile function copies the file from the source path to the specified destination.

Parameters: DS:AX - pointer to the string with the source file name; ES:BX - pointer to the string with the destination path.

Return value: On success (CF=0) the file is copied; 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 CopyFile function to copy a file.

title Author: Evgeny Sergeevich Dovgopolov

.model small
.stack 100h

data segment public
    path  db "folder\\0", 0
    fname db "test.txt", 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:[path]   ; Load the address of the string path into the es:bx register
        lea     ax, ds:[fname]  ; Load the address of the string fname into the ds:ax register
        call    CopyFile        ; Call the CopyFile procedure (ax:fname, bx:path) := CF

        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 function does not print a success or error message, it only changes the flags)

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