Arquivos - copiando arquivos |
Top Previous Next |
|
Não é necessário um componente. Você pode criar sua própria função de cópia utilizando uma função da API (LZCopy), rápida e eficiente. Veja exemplo abaixo
implementation
{$R *.DFM}
function LZCopy(Source, Dest: Integer): Longint; far; external 'LZEXPAND';
procedure TfrmSETUP.CopiaArq(origem,destino: string); var F,D: integer; begin f:=FileOpen(origem,0); d:=FileCreate(destino); LZCopy(f,d); FileClose(f); FileClose(d); end;
=============== MANEIRA 2 =======================
procedure CopiaArquivos(ArqEnt,ArqSai : String); var StrmEnt, StrmSai : TFileStream; begin StrmEnt := TFileStream.Create(ArqEnt,fmOpenRead); try StrmSai := TFileStream.Create(ArqSai, fmOpenWrite or fmCreate); try StrmSai.CopyFrom(StrmEnt, StrmEnt.Size); finally StrmSai.Free; end; finally StrmEnt.Free; end; end;
procedure TForm1.Button1Click(Sender: TObject); begin CopiaArquivos('unit1.pas','unit1.old'); end;
=============== MANEIRA 3 =======================
// Utilize asteristico para a seleção dos arquivos. Ex.: c:\*.* ou *.txt // Declare ShellAPI na uses. procedure COPY_FILES(Source, Dest : string); var FOS : TSHFileOpStruct; CopySourceString : String; CopyDestString : String; begin ZeroMemory(@FOS, sizeof(TSHFileOpStruct)); CopySourceString := Source + #0#0; CopyDestString := Dest; with FOS do begin Wnd := Application.Handle; wFunc := FO_COPY; pFrom := Pchar(CopySourceString); pTo := Pchar(CopyDestString); fFlags := FOF_SIMPLEPROGRESS; fAnyOperationsAborted := True; lpszProgressTitle := Pchar(Application.Title); end; SHFileOperation(FOS); end; |