procedure FastFileCopyCallBack(Position, Size: longint);
begin
Form1.ProgressBar1.Max := Size;
Form1.ProgressBar1.Position := Position;
Form1.ProgressBar1.Update
end;
procedure FastFileCopy(
const InFileName, OutFileName:
string; CallBack: TCallBack);
const
BufSize = 3 * 4 * 4096;
{ 48Kbytes gives me the best results }
type
PBuffer = ^TBuffer;
TBuffer =
array[1..BufSize]
of Byte;
var
Size: DWORD;
Buffer: PBuffer;
infile, outfile:
file;
SizeDone, SizeFile: LongInt;
begin
buffer :=
nil;
if (InFileName <> OutFileName)
then
try
try
AssignFile(infile, InFileName);
Reset(infile, 1);
AssignFile(outfile, OutFileName);
Rewrite(outfile, 1);
SizeDone := 0;
SizeFile := FileSize(infile);
Callback (0, SizeFile);
New(Buffer);
repeat
BlockRead(infile, Buffer^, BufSize, Size);
Inc(SizeDone, Size);
BlockWrite(outfile, Buffer^, Size);
Callback (SizeDone, SizeFile)
until Size < BufSize;
FileSetDate(TFileRec(outfile).Handle, FileGetDate(TFileRec(infile).Handle));
except
// Exception behandeln
end
finally
if Buffer <>
nil then
Dispose(Buffer);
CloseFile(outfile);
CloseFile(infile)
end
else
raise EInOutError.Create('
File cannot be copied onto itself')
end;