Last modified: July 23, 2011

Applies to: Outlook

Copies or moves a folder from its current parent folder to another parent folder.

HRESULT CopyFolder(
  LPCIID lpSrcInterface,
  LPVOID lpSrcFolder,
  ULONG cbEntryID,
  LPCIID lpInterface,
  LPVOID lpDestFolder,
  LPSTR lpszNewFolderName,
  ULONG_PTR ulUIParam,
  ULONG ulFlags


[in] A pointer to the interface identifier (IID) that represents the interface to be used to access the parent folder of the folder to be copied or moved.


[in] A pointer to the parent folder of the folder to be copied or moved.


[in] The byte count in the entry identifier pointed to by lpEntryID.


[in] A pointer to the entry identifier of the folder to be copied or moved.


[in] Reserved; must be NULL.


[in] A pointer to the folder that is to receive the folder to be copied or moved.


[in] A pointer to the name of the copied or moved folder; otherwise, NULL, which indicates that the copied or moved folder should have the same name as the source folder (the folder pointed to by lpEntryID).


[in] A handle of the window for the progress indicator dialog box and related windows. The ulUIParam parameter is ignored unless the FOLDER_DIALOG flag is set in the ulFlags parameter.


[in] A pointer to a progress object that displays a progress indicator. If NULL is passed in lpProgress, the message store provider displays a progress indicator by using the MAPI progress object implementation. The lpProgress parameter is ignored unless the FOLDER_DIALOG flag is set in ulFlags.


[in] A bitmask of flags that controls how the copy or move operation is accomplished. The following flags can be set:


All of the folder's subfolders should be copied or moved. When COPY_SUBFOLDERS is not set for a copy operation, only the folder identified by lpEntryID is copied. With a move operation, the COPY_SUBFOLDERS behavior is the default regardless of whether the flag is set.


Requests the display of a progress indicator.


The folder should be moved instead of copied. If FOLDER_MOVE is not set, the folder is copied.


The name of the folder is in Unicode format. If the MAPI_UNICODE flag is not set, the name of the folder is in ANSI format.


The folder has been successfully copied or moved.


The name of the folder being moved or copied is the same as that of a subfolder in the destination folder. The message store provider requires that folder names be unique. The operation stops without completing.


The call succeeded, but not all entries were successfully copied. When this warning is returned, the call should be handled as successful. To test for this warning, use the HR_FAILED macro. For more information, see Using Macros for Error Handling.

The IMAPISupport::CopyFolder method is implemented for message store provider support objects. Message store providers can call IMAPISupport::CopyFolder in their implementation of IMAPIFolder::CopyFolder to copy or move a single folder from one parent folder to another.

IMAPISupport::CopyFolder adds the copied or moved folder as a subfolder of the destination folder.

IMAPISupport::CopyFolder allows simultaneous renaming and moving of folders and the copying or moving of subfolders of the affected folder. To copy or move all subfolders nested in the copied or moved folder, pass the COPY_SUBFOLDERS flag in ulFlags.

Expect the following return values under the following conditions:


Return value

CopyFolder successfully copied or moved the folder and all its subfolders, if applicable.


CopyFolder was unable to successfully copy or move all of the folders.


CopyFolder was unable to complete.

Any error value

If CopyFolder returns an error value, do not proceed on the assumption that no work was done. One or more folders could have been copied or moved before CopyFolder experienced the failure.