All pastes #912075 Raw Edit

CroZBr

public text v1 · immutable
·published 2008-02-21 03:06 UTC
rendered paste body
Function CopyFileEx(Src,Dst: string; Block: cardinal; const Attributes: cardinal = 1):cardinal;
var
hSrc,hDst: HWND;
Size,Loop,Writed,Readed: cardinal;
Buff: array of byte;
begin
Result := 0;
hSrc := CreateFile(pchar(src), generic_read, 0, nil, open_always, 0, 0);
if hSrc = INVALID_HANDLE_VALUE then exit;
hDst := CreateFile(pchar(dst), generic_write,0, nil, create_always,Attributes, 0);
if hDst = INVALID_HANDLE_VALUE then exit;
Size := GetFileSize(hSrc, nil);
if Size <> 0 then begin
 SetLength(Buff, Block);
  For Loop := 0 to Size div block - 1 do begin
   SetFilePointer(hSrc, Loop, nil, FILE_BEGIN);
   ReadFile(hSrc, Buff, block, Readed, nil);
   WriteFile(hDst,Buff, Readed,Writed, nil);
  end;
 if Loop * block < Size then begin
   ReadFile(hSrc, Buff, Size - Loop * block, Readed, nil);
   WriteFile(hDst,Buff, Readed,Writed, nil);
 end;
end;
CloseHandle(hSrc);
CloseHandle(hDst);
end;