以下一段代码是从MSDN拷贝过来的,关于从一个文件夹复制到另外一个文件夹.麻烦哪位大侠翻译成
delphi的pas,谢谢#include <shlobj.h>
#include <shlwapi.h>main()
{
    IShellFolder *psfDeskTop = NULL;
    IShellFolder *psfDocFiles = NULL;
    IMalloc *pMalloc = NULL;
    LPITEMIDLIST pidlDocFiles = NULL;
    LPITEMIDLIST pidlItems = NULL;
    IEnumIDList *ppenum = NULL;
    SHFILEOPSTRUCT sfo;
    STRRET strDispName;
    TCHAR szParseName[MAX_PATH];
    TCHAR szSourceFiles[256];
    int i;
    int iBufPos = 0;
    ULONG chEaten;
    ULONG celtFetched;
    HRESULT hr;    pzSourceFiles[0] = '\0';
    hr = SHGetMalloc(&pMalloc);
    hr = SHGetDesktopFolder(&psfDeskTop);    hr = psfDeskTop->ParseDisplayName(NULL, NULL, L"c:\\My_Docs", 
         &chEaten, &pidlDocFiles, NULL);
    hr = psfDeskTop->BindToObject(pidlDocFiles, NULL, IID_IShellFolder, 
         (LPVOID *) &psfDocFiles);
    hr = psfDeskTop->Release();    hr = psfDocFiles->EnumObjects(NULL,SHCONTF_FOLDERS | SHCONTF_NONFOLDERS, 
         &ppenum);    while( (hr = ppenum->Next(1,&pidlItems, &celtFetched)) == S_OK 
       && (celtFetched) == 1)
    {
        psfDocFiles->GetDisplayNameOf(pidlItems, SHGDN_FORPARSING, 
            &strDispName);
        StrRetToBuf(&strDispName, pidlItems, szParseName, MAX_PATH);
        for(i=0;i<=lstrlen(szParseName); i++)
        {
            szSourceFiles[iBufPos++] = szParseName[i];
        }
        pMalloc->Free(pidlItems);
    }
ppenum->Release();

    szSourceFiles[iBufPos] = '\0';    sfo.hwnd = NULL;
    sfo.wFunc = FO_COPY;
    sfo.pFrom = szSourceFiles;
    sfo.pTo = "c:\\My_Docs2\0";
    sfo.fFlags = FOF_SILENT | FOF_NOCONFIRMATION | FOF_NOCONFIRMMKDIR;    hr = SHFileOperation(&sfo);

    SHChangeNotify(SHCNE_UPDATEDIR, SHCNF_PATH, (LPCVOID) "c:\My_Docs2", 0);    pMalloc->Free(pidlDocFiles);
    psfDocFiles->Release();    return 0;
}

解决方案 »

  1.   

    干嘛,用delphi自己的不行吗
      

  2.   

    其實關鍵只是兩三個函數的使用而已, 參考這裹:http://hubdog.csdn.net/Recommend/rcFolder.htm
    http://delphi.ktop.com.tw/TOPIC.ASP?TOPIC_ID=25818
      

  3.   

    关于从一个文件夹复制到另外一个文件夹
    这段代码写的很清楚:
        sfo.hwnd = NULL;
        sfo.wFunc = FO_COPY;
        sfo.pFrom = szSourceFiles;
        sfo.pTo = "c:\\My_Docs2\0";
        sfo.fFlags = FOF_SILENT | FOF_NOCONFIRMATION | FOF_NOCONFIRMMKDIR; 
      SHFileOperation(&sfo);
    -----------------------复制主要用这个函数---1。SHFILEOPSTRUCT sfo;这是这个函数需要的结构体
    译成D版:
     var
    sfo: TSHFILEOPSTRUCT;
    2。然后把sfo的结构提填充好。
    3。用SHFileOperation执行感觉D版比上边的还简单
      

  4.   

    就是嘛,你看看他实现的功能,DELPHI简单得多,unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, ShellApi;type
      TForm1 = class(TForm)
        procedure FormCreate(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.dfm}procedure TForm1.FormCreate(Sender: TObject);
    var
      T: TSHFileOpStruct;
      frombuf, tobuf: Array [0..MAX_PATH-1] of Char;
    Begin
      FillChar(frombuf, Sizeof(frombuf), 0 );
      FillChar(tobuf, Sizeof(tobuf), 0 );
      StrPCopy(frombuf,ExtractFileDir(Application.ExeName));
      StrPCopy(tobuf, 'c:\test' );
      with T do
      begin
        Wnd:= Handle;
        wFunc:= FO_COPY;
        pFrom:= @frombuf;
        pTo:=@tobuf;
        fFlags:= FOF_NOCONFIRMATION or FOF_RENAMEONCOLLISION;
        fAnyOperationsAborted:= False;
        hNameMappings:= nil;
        lpszProgressTitle:= nil;
      end;
      ShFileOperation( T );
    end;
    end.
      

  5.   

    我还以为这是ShFileOperation的实现方法.
    我想了解它是如何实现递归.
    该问题我另外已经想办法马马虎虎算解决了.