怎么把任何类型的文件实行复制,如把C:\aa\abc.mdb复制到d:\bb\dd.mdb呢?

解决方案 »

  1.   

    procedure TForm1.copyPathFile(strSourFilePath:string;DeFieldpath:string);//将一个文件夹内文件复制到另外一个文件夹内
    var
     OpStruc:TSHFileOpStruct;
      FromBuf,ToBuf:Array[0..128] of Char;
    begin
      try
        FillChar(FromBuf,Sizeof(FromBuf),0);
        FillChar(ToBuf,Sizeof(ToBuf),0);
        StrPCopy(FromBuf,Pchar(strSourFilePath));
    //strSourFilePath
        StrPCopy(ToBuf,Pchar(DeFieldpath));
           with OpStruc do
        begin
          Wnd:=handle;
          wFunc:=FO_COPY;
          pFrom:=@FromBuf;
          pTo:=@ToBuf;
          fFlags:=FOF_NOCONFIRMATION or FOF_MULTIDESTFILES or FOF_SIMPLEPROGRESS;// or FOF_RENAMEONCOLLISION;
          fAnyOperationsAborted:=False;
          hNameMappings:=nil;
          lpszProgressTitle:=nil;
        end;
        if SHFileOperation(OpStruc)=0 then
        begin
        end;
      except
        raise Exception.Create('错误');
      end;
    end;
      

  2.   

    用这个API干净利落
    BOOL CopyFile(
        LPCTSTR lpExistingFileName,// pointer to name of an existing file 
        LPCTSTR lpNewFileName, // pointer to filename to copy to 
        BOOL bFailIfExists  // flag for operation if file exists 
       );
      

  3.   

    copyfileA(pchar('C:\aa\abc.mdb'),pchar('d:\bb\dd.mdb'),false);这样就OK了,非常简单
      

  4.   

    copyfileA(pchar('C:\aa\abc.mdb'),pchar('d:\bb\dd.mdb'),false);这种方法更简单