Skip to content

Latest commit

 

History

History
253 lines (206 loc) · 7.33 KB

nf-winbase-copyfile2.md

File metadata and controls

253 lines (206 loc) · 7.33 KB
UID title description helpviewer_keywords old-location tech.root ms.assetid ms.date ms.keywords req.header req.include-header req.target-type req.target-min-winverclnt req.target-min-winversvr req.kmdf-ver req.umdf-ver req.ddi-compliance req.unicode-ansi req.idl req.max-support req.namespace req.assembly req.type-library req.lib req.dll req.irql targetos req.typenames req.redist ms.custom f1_keywords dev_langs topic_type api_type api_location api_name
NF:winbase.CopyFile2
CopyFile2 function (winbase.h)
Copies an existing file to a new file, notifying the application of its progress through a callback function. (CopyFile2)
CopyFile2
CopyFile2 function [Files]
fs.copyfile2
winbase/CopyFile2
fs\copyfile2.htm
fs
aa2df686-4b61-4d90-ba0b-c78c5a0d2d59
12/05/2018
CopyFile2, CopyFile2 function [Files], fs.copyfile2, winbase/CopyFile2
winbase.h
Windows.h
Windows
Windows 8 [desktop apps \| UWP apps]
Windows Server 2012 [desktop apps \| UWP apps]
Kernel32.lib
Kernel32.dll
Windows
19H1
CopyFile2
winbase/CopyFile2
c++
APIRef
kbSyntax
DllExport
Kernel32.dll
API-MS-Win-Core-File-l2-1-0.dll
KernelBase.dll
API-MS-Win-Core-File-l2-1-1.dll
API-MS-Win-Core-File-l2-1-2.dll
CopyFile2

CopyFile2 function

-description

Copies an existing file to a new file, notifying the application of its progress through a callback function.

-parameters

-param pwszExistingFileName [in]

The name of an existing file.

To extend this limit to 32,767 wide characters, prepend "\?" to the path. For more information, see Naming Files, Paths, and Namespaces.

Tip  Starting in Windows 10, version 1607, you can opt-in to remove the MAX_PATH character limitation without prepending "\\?\". See the "Maximum Path Limitation" section of Naming Files, Paths, and Namespaces for details.
 
If lpExistingFileName does not exist, the CopyFile2 function fails returns HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND).

-param pwszNewFileName [in]

The name of the new file.

To extend this limit to 32,767 wide characters, prepend "\?" to the path. For more information, see Naming Files, Paths, and Namespaces.

Tip  Starting in Windows 10, version 1607, you can opt-in to remove the MAX_PATH character limitation without prepending "\\?\". See the "Maximum Path Limitation" section of Naming Files, Paths, and Namespaces for details.
 

-param pExtendedParameters [in, optional]

Optional address of a COPYFILE2_EXTENDED_PARAMETERS structure.

-returns

If the function succeeds, the return value will return TRUE when passed to the SUCCEEDED macro.

Return code Description
S_OK
The copy operation completed successfully.
HRESULT_FROM_WIN32(ERROR_REQUEST_PAUSED)
The copy operation was paused by a COPYFILE2_PROGRESS_PAUSE return from the CopyFile2ProgressRoutine callback function.
HRESULT_FROM_WIN32(ERROR_REQUEST_ABORTED)
The copy operation was paused by a COPYFILE2_PROGRESS_CANCEL or COPYFILE2_PROGRESS_STOP return from the CopyFile2ProgressRoutine callback function.
HRESULT_FROM_WIN32(ERROR_ALREADY_EXISTS)
The dwCopyFlags member of the COPYFILE2_EXTENDED_PARAMETERS structure passed through the pExtendedParameters parameter contains the COPY_FILE_FAIL_IF_EXISTS flag and a conflicting name existed.
HRESULT_FROM_WIN32(ERROR_FILE_EXISTS)
The dwCopyFlags member of the COPYFILE2_EXTENDED_PARAMETERS structure passed through the pExtendedParameters parameter contains the COPY_FILE_FAIL_IF_EXISTS flag and a conflicting name existed.

-remarks

This function preserves extended attributes, OLE structured storage, NTFS file system alternate data streams, and file attributes. Security attributes for the existing file are not copied to the new file. To copy security attributes, use the SHFileOperation function.

This function fails with HRESULT_FROM_WIN32(ERROR_ACCESS_DENIED) if the destination file already exists and has the FILE_ATTRIBUTE_HIDDEN or FILE_ATTRIBUTE_READONLY attribute set.

To compile an application that uses this function, define the _WIN32_WINNT macro as _WIN32_WINNT_WIN8 or later. For more information, see Using the Windows Headers.

In Windows 8 and Windows Server 2012, this function is supported by the following technologies.

Technology Supported
Server Message Block (SMB) 3.0 protocol Yes
SMB 3.0 Transparent Failover (TFO) Yes
SMB 3.0 with Scale-out File Shares (SO) Yes
Cluster Shared Volume File System (CsvFS) Yes
Resilient File System (ReFS) Yes

Starting with Windows 10, version 1903 and Windows Server 2022, a new value, COPY_FILE_REQUEST_COMPRESSED_TRAFFIC, is supported for the dwCopyFlags field of the COPYFILE2_EXTENDED_PARAMETERS structure passed in the pExtendedParameters argument to this function. This new value requests that the underlying transfer channel compress the data during the copy operation. The request may not be supported for all mediums, in which case it is ignored. The compression attributes and parameters (computational complexity, memory usage) are not configurable through this API, and are subject to change between different OS releases. On Windows 10, the flag is supported for files residing on SMB shares, where the negotiated SMB protocol version is SMB v3.1.1 or greater.

-see-also

COPYFILE2_EXTENDED_PARAMETERS

File Management Functions