CopyFile function
The CopyFile function copies an existing file to a new location.
This function is part of the Win32 API.
Syntax
BOOL CopyFile(
LPCTSTR lpExistingFileName,
LPCTSTR lpNewFileName,
BOOL bFailIfExists
);
Parameters
-
lpExistingFileNameThe name of an existing file.
-
lpNewFileNameThe name of the new file.
-
bFailIfExistsSpecifies whether the function should fail if the new file already exists.
- If this parameter is
TRUEand the new file exists, the function fails. - If this parameter is
FALSEand the new file exists, the function overwrites the existing file.
- If this parameter is
Return Value
BOOL
If the function succeeds, the return value is nonzero.
If the function fails, the return value is zero. To get extended error information, call GetLastError.
Remarks
If the destination file exists and the bFailIfExists parameter is FALSE, CopyFile overwrites the destination file. If the destination file exists and bFailIfExists is TRUE, the function returns FALSE and GetLastError returns ERROR_FILE_EXISTS.
This function does not support copying directories. Use SHCopyDirectoryEx or similar functions for directory copying.
For more advanced copy operations, such as copying with progress indicators or specific flags, consider using CopyFileEx.
Requirements
Client: Windows XP and later
Server: Windows Server 2003 and later
Header: winbase.h (include windows.h)
Library: Use Kernel32.lib