uses FileCtrl, ShellAPI;
var  OpStruc: SHFileOpStruct;         sSourceFileName:=sCurPath+'\CD_Maker\*.*';
             sTargetFileName:=sCurPath+'\CDROM';
             With OpStruc DO
                 Begin
                       Wnd:=0;
                       wFunc:= FO_COPY;
                       pFrom:=PChar(sSourceFileName);
                       pTo:=PChar(sTargetFileName);
                       //fFlags:= FOF_RENAMEONCOLLISION ;
                       fFlags:= FOF_NOCONFIRMATION OR FOF_RENAMEONCOLLISION;
                       fAnyOperationsAborted:= FALSE;
                       hNameMappings:= Nil;
                       lpszProgressTitle:= Nil;
                  End;
             boolAssistantCopyOK:=(ShFileOperation(OpStruc)=0);
    

解决方案 »

  1.   

    function TMainForm.CopyDir(FromDir, ToDir: string): boolean;
    var T         : TSHFileOpStruct;
    begin
            With T do
            Begin
              //Wnd:=Fm_Create_Question.Handle ;
              Wnd:=Application.Handle;
              wFunc:=FO_COPY ;
              pFrom:=Pchar(FromDir);
              pTo:=pchar(ToDir);
              hNameMappings:=nil;
              lpszProgressTitle:=nil;
              fFlags:=FOF_NOCONFIRMATION;
            End;
            SHFileOperation(T);
            result := true;
    end;
      

  2.   

    使用TSHFileOpStruct时偶尔会出现:源文件无法读取之类的错误!偶用的是2k Adv Server,Delphi 6,不知道是什么问题?(后来我用的递归拷贝的!)
      

  3.   

    Copies or moves one or more messages in the current folder to another.SyntaxHRESULT CopyFolder(ULONG cbEntryID, LPENTRYID lpEntryID, LPCIID lpInterface, LPVOID lpDestFolder, LPTSTR lpszNewFolderName, ULONG ulUIParam, LPMAPIPROGRESS lpProgress, ULONG ulFlags)ParameterscbEntryIDInput parameter containing the number of bytes in the entry identifier pointed to by the lpEntryID parameter.lpEntryIDInput parameter pointing to the entry identifier of the folder to copy or move.lpInterfaceInput parameter pointing to the interface identifier (IID) for the destination folder object indicated in the lpDestFolder parameter. Passing NULL for the lpInterface parameter indicates the MAPI interface for the destination folder object will be returned. Client applications must pass NULL. Message store providers can also set the lpInterface parameter to an identifier for another appropriate interface for the destination folder object. For example, a message can be copied with IID_IUnknown, IID_IMAPIProp, IID_IMAPIContainer, or IID_IMAPIFolder.lpDestFolderInput parameter pointing to the open destination folder where the folder identified in the lpEntryID parameter is copied or moved.lpszNewFolderNameInput parameter pointing to a string containing the name to be given to the newly created or moved folder. If the client application passes NULL in the lpszNewFolderName parameter, the name of the newly created or moved folder is the same as the name of the original.ulUIParamInput parameter containing the handle to the window the dialog box is modal to. The ulUIParam parameter is ignored unless the client application sets the FOLDER_DIALOG flag in the ulFlags parameter and passes NULL in the lpProgress
     parameter.lpProgressInput parameter pointing to a progress object that contains client-supplied progress information. If NULL is passed in the 
    lpProgress parameter, the progress information is provided by MAPI. The lpProgress parameter is ignored unless the FOLDER_DIALOG flag is set in the ulFlags parameter.ulFlagsInput parameter containing a bitmask of flags used to control how the copy or move operation is accomplished. The following flags can be set:COPY_SUBFOLDERSIndicates that all subfolders are included in the copy operation. This is optional for copy operations and is implied for move operations.FOLDER_DIALOGDisplays a progress-information user interface while the operation proceeds.FOLDER_MOVEIndicates that the folder is to be moved. If this flag is not set, the folder will be copied.MAPI_DECLINE_OKInforms the provider that if it chooses not to implement IMAPIFolder::CopyFolder, that it can immediately return MAPI_E_DECLINE_COPY. MAPI_UNICODEIndicates the passed-in strings are in Unicode format. If the MAPI_UNICODE flag is not set, the strings are in 8-bit format.Return ValuesS_OKThe call succeeded and has returned the expected value or values.MAPI_E_BAD_CHARWIDTHEither the MAPI_UNICODE flag was set and the implementation does not support Unicode, or MAPI_UNICODE was not set and the implementation only supports Unicode.MAPI_E_COLLISIONThe name of the folder being moved is the same as the name of a sub-folder in the destination folder. Folder names must be unique.MAPI_E_DECLINE_COPYIndicates that the provider has chosen not to implement this operation.MAPI_E_FOLDER_CYCLEThe source object directly or indirectly contains the destination object. Significant work might have been performed before this condition was discovered so the source and destination object might be partially modified. MAPI_W_PARTIAL_COMPLETIONThe call succeeded, but not all entries were successfully copied. Use the HR_FAILED macro to test for this warning, but the call should be handled as a successful return.CommentsMessage store providers use the IMAPIFolder::CopyFolder method to copy or move folders from one location to another. The folder being copied or moved is added to the destination folder as a subfolder. Only one folder can be copied or moved at a time.
    CopyFolder allows simultaneous renaming and moving of folders and the copying or moving of the subfolders of the affected folder. To copy or move all subfolders nested within the copied or moved folder, the client application passes the COPY_SUBFOLDERS flag in the ulFlags parameter. To allow copy or move operations involving more than one folder to continue even if one or more folders specified for the operation do not exist or have already been moved elsewhere, and thus cannot be copied or moved, a message store provider should attempt to complete the operation as best it can for each folder specified. The provider should stop the operation without completing it only in the case of failures it cannot control, such as running out of memory or disk space, message store corruption, and so on.If CopyFolder successfully completes the copy or move operation for every folder requested by the client application, it returns the value S_OK. If one or more folders cannot be copied or moved, CopyFolder returns the value MAPI_W_PARTIAL_COMPLETION. If CopyFolder returns a different value, such as MAPI_E_NOT_ENOUGH_MEMORY, that indicates the call did not complete, though it might already have copied or moved one or more folders without being able to continue. The calling application cannot proceed on the assumption that an error return implies no work was done.If an entry identifier for a folder that doesn't exist is passed in the lpEntryID parameter, CopyFolder returns MAPI_W_PARTIAL_COMPLETION or MAPI_E_NOT_FOUND, depending on a message store's implementation.