求多线程复制代码
1、要能复制大文件(1G左右)
2、要有复制进度
-----------------------------
下面的代码看看,复制大于10M左右的文件就不行了
程序忙得要死!
--------------------------
procedure TForm1.Copy_File(Source:string ;Destination:string);
var
FromF,ToF: file ;
Buffer : array[0..4096] of char;
NumRead : integer;
FileLength : longint;
begin
AssignFile(FromF,Source);
reset(FromF,1);
AssignFile(ToF,Destination);
rewrite(ToF,1);
FileLength:=FileSize(FromF);
With Form1.ProgressBar1 do
begin
Min := 0;
Max := FileLength;
while FileLength > 0 do
begin
BlockRead(FromF,Buffer[0],SizeOf(Buffer),NumRead);
FileLength := FileLength - NumRead;
BlockWrite(ToF,Buffer[0],NumRead);
Position := Position + NumRead;
end;
CloseFile(FromF);
CloseFile(ToF);
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
copy_file('C:\111\System.dat','C:\222\System.dat' );
end;
1、要能复制大文件(1G左右)
2、要有复制进度
-----------------------------
下面的代码看看,复制大于10M左右的文件就不行了
程序忙得要死!
--------------------------
procedure TForm1.Copy_File(Source:string ;Destination:string);
var
FromF,ToF: file ;
Buffer : array[0..4096] of char;
NumRead : integer;
FileLength : longint;
begin
AssignFile(FromF,Source);
reset(FromF,1);
AssignFile(ToF,Destination);
rewrite(ToF,1);
FileLength:=FileSize(FromF);
With Form1.ProgressBar1 do
begin
Min := 0;
Max := FileLength;
while FileLength > 0 do
begin
BlockRead(FromF,Buffer[0],SizeOf(Buffer),NumRead);
FileLength := FileLength - NumRead;
BlockWrite(ToF,Buffer[0],NumRead);
Position := Position + NumRead;
end;
CloseFile(FromF);
CloseFile(ToF);
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
copy_file('C:\111\System.dat','C:\222\System.dat' );
end;
);
ParameterslpFileOpPointer to an SHFILEOPSTRUCT structure that contains information the function needs to carry out the operation. Return ValuesReturns zero if successful or nonzero if an error occurs. See AlsoSHFILEOPSTRUCT
你说什么,偶不懂 ~#_#~
是不是:
var
shfos: SHFILEOPSTRUCT;
sFrom, sTo: string;
begin
sFrom := 'c:\test\*.*';
sTo := 'd:\test\';
with shfos do begin
shfos.Wnd := Handle;
wFunc := FO_COPY;
shfos.pFrom := PChar(sFrom + #0);
shfos.pTo := PChar(sTo + #0);
fAnyOperationsAborted := True;
shfos.fFlags := FOF_ALLOWUNDO;
end;
SHFileOperation(shfos);
end;
不是多线程呀
你是想要文件复制的"算法"还是想问如何用createthread建立和执行线程?