다음을 통해 공유


IFileOperation::CopyItem 메서드(shobjidl_core.h)

지정된 대상에 복사할 단일 항목을 선언합니다.

구문

HRESULT CopyItem(
  [in] IShellItem                 *psiItem,
  [in] IShellItem                 *psiDestinationFolder,
  [in] LPCWSTR                    pszCopyName,
  [in] IFileOperationProgressSink *pfopsItem
);

매개 변수

[in] psiItem

형식: IShellItem*

원본 항목을 지정하는 IShellItem 에 대한 포인터입니다.

[in] psiDestinationFolder

형식: IShellItem*

항목의 복사본을 포함할 대상 폴더를 지정하는 IShellItem 에 대한 포인터입니다.

[in] pszCopyName

형식: LPCWSTR

항목이 복사된 후의 새 이름에 대한 포인터입니다. null로 끝나는 유니코드 문자열이며 NULL일 수 있습니다. NULL인 경우 대상 항목의 이름은 원본과 동일합니다.

[in] pfopsItem

형식: IFileOperationProgressSink*

이 특정 복사 작업에 대한 진행률 상태 및 오류 알림에 사용할 IFileOperationProgressSink 개체에 대한 포인터입니다. 전체 작업에 대해 IFileOperation::Advise를 호출하면 복사 작업에 대한 진행률 상태 및 오류 알림이 포함되므로 이 매개 변수를 NULL로 설정합니다.

반환 값

형식: HRESULT

메서드가 성공하면 S_OK를 반환하고, 그러지 않으면 HRESULT 오류 코드를 반환합니다.

설명

이 메서드는 항목을 복사하지 않고 복사할 항목을 선언합니다. 개체를 복사하려면 적어도 여기에 자세히 설명된 호출 시퀀스를 만들어야 합니다.

  1. IFileOperation::CopyItem을 호출하여 원본 항목, 대상 폴더 및 대상 이름을 선언합니다.
  2. IFileOperation::P erformOperations를 호출하여 복사 작업을 시작합니다.

예제

다음 예제 코드는 이 메서드의 샘플 구현을 보여줍니다.

HRESULT CopyItem(__in PCWSTR pszSrcItem, __in PCWSTR pszDest, PCWSTR pszNewName)
{
    //
    // Initialize COM as STA.
    //
    HRESULT hr = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE); 
    if (SUCCEEDED(hr))
    {
        IFileOperation *pfo;
  
        //
        // Create the IFileOperation interface 
        //
        hr = CoCreateInstance(CLSID_FileOperation, 
                              NULL, 
                              CLSCTX_ALL, 
                              IID_PPV_ARGS(&pfo));
        if (SUCCEEDED(hr))
        {
            //
            // Set the operation flags. Turn off all UI from being shown to the
            // user during the operation. This includes error, confirmation,
            // and progress dialogs.
            //
            hr = pfo->SetOperationFlags(FOF_NO_UI);
            if (SUCCEEDED(hr))
            {
                //
                // Create an IShellItem from the supplied source path.
                //
                IShellItem *psiFrom = NULL;
                hr = SHCreateItemFromParsingName(pszSrcItem, 
                                                 NULL, 
                                                 IID_PPV_ARGS(&psiFrom));
                if (SUCCEEDED(hr))
                {
                    IShellItem *psiTo = NULL;
  
                    if (NULL != pszDest)
                    {
                        //
                        // Create an IShellItem from the supplied 
                        // destination path.
                        //
                        hr = SHCreateItemFromParsingName(pszDest, 
                                                         NULL, 
                                                         IID_PPV_ARGS(&psiTo));
                    }
                    
                    if (SUCCEEDED(hr))
                    {
                        //
                        // Add the operation
                        //
                        hr = pfo->CopyItem(psiFrom, psiTo, pszNewName, NULL);

                        if (NULL != psiTo)
                        {
                            psiTo->Release();
                        }
                    }
                    
                    psiFrom->Release();
                }
                
                if (SUCCEEDED(hr))
                {
                    //
                    // Perform the operation to copy the file.
                    //
                    hr = pfo->PerformOperations();
                }        
            }
            
            //
            // Release the IFileOperation interface.
            //
            pfo->Release();
        }
  
        CoUninitialize();
    }
    return hr;
}

요구 사항

요구 사항
지원되는 최소 클라이언트 Windows Vista [데스크톱 앱만 해당]
지원되는 최소 서버 Windows Server 2008 [데스크톱 앱만 해당]
대상 플랫폼 Windows
헤더 shobjidl_core.h(Shobjidl.h 포함)

추가 정보

IFileOperation

IFileOperation::CopyItems

PostCopyItem

PreCopyItem