2.1.10.5 CopyFile


Description

This function copies an existing file to a new file

Syntax

BOOL CopyFile( LPCSTR lpExistingFileName, LPCSTR lpNewFileName, BOOL bFailIfExists = FALSE )

Parameters

lpExistingFileName
[input] Pointer to a null-terminated string that specifies the name of an existing file.
lpNewFileName
[input] Pointer to a null-terminated string that specifies the name of the new file.
The name is limited to MAX_PATH characters.
bFailIfExists
[input] Specifies how this operation is to proceed if a file of the same name as that specified by lpNewFileName already exists.
If this parameter is TRUE and the new file already exists, the function fails.
If this parameter is FALSE and the new file already exists, the function overwrites the existing file and succeeds.

Return

TRUE for success.

Examples

EX1

int    CopyFile_ex1()
{
    string strTemp = GetAppPath() + "Origin.ini";
    string strNew =  GetAppPath() + "junk.ini";
    if(!strTemp.IsFile())
    {
        out_str("No Origin.ini found");
        return 0 ;
    }
    if(strNew.IsFile())
        out_str("junk.ini already existed before we copy");

    if (!CopyFile(strTemp, strNew)) 
    {
        out_str("Copy file failed");
        return 0;
    }
    if(!strNew.IsFile())
        out_str("Error: Copy file did not create the junk.ini even though it said it did");
    return 1;
}

Remark

See Also

MoveFile

Header to Include

origin.h

Reference