恩....手边没现成代码,只有个多文件复制的
思路大概是这样:
先用类似下面的代码取得你要复制的目录的全部结构:
if FindFirst(tmpPath+'*.*',faAnyFile,SRec)=0 then
repeat
If (srec.Attr and FILE_ATTRIBUTE_DIRECTORY)<>0 then
{这个是目录}
//记下目录 tmpPath+srec.Name 并且用CreateDirectory创建目录
else
//记下文件 tmpPath+srec.Name 并且取得文件字节大小
until FindNext( SRec )<>0;
存起来
然后再用下面的代码复制文件并显示进度
进度条的总长度应该为全部文件的大小或者数量,具体用哪个你自己选
下面的例子是文件数量的
var
SrcFile, DestFile: File;
BytesRead, BytesWritten, TotalRead: Integer;
Buffer: array[1..500] of byte;
FSize,i,intfiles,x: Integer;
fname:string;
begin
if cb_copy.Checked then
begin
if edt_topath.Text='' then
begin
application.MessageBox('先选择目标路径!','提示',mb_ok);
exit;
end;
fname:='';
intfiles:=0;
if CB_all.Checked then
intfiles:=lv_file.Items.Count
else
for i:=0 to lv_file.Items.Count-1do
if lv_file.Items.Selected then
intfiles:=intfiles+1;
ProgressBar2.Max:=intfiles;
{这里,进度条总长度为文件的总数量}
ProgressBar2.Step:=1;
x:=strtoint(edit3.Text);
for i:=0 to lv_file.Items.Count-1do
begin
if not CB_all.Checked then
if not lv_file.Items.Selected then
continue;
AssignFile(SrcFile,edt_frompath.Text+'/'+lv_file.Items.Caption);
fname:=inttostr(i+x)+copy(lv_file.Items.Caption,pos('.',lv_file.Items.Caption),length(lv_file.Items.Caption));
StatusBar1.Panels.Items[1].Text:=lv_file.Items.Caption+'---->'+fname;
AssignFile(DestFile, edt_topath.Text+'/'+fname);
Reset(SrcFile, 1);
try
Rewrite(DestFile, 1);
try
try
TotalRead := 0;
FSize := FileSize(SrcFile);
ProgressBar1.min:=0;
ProgressBar1.max:=trunc(fsize/500);
repeat
BlockRead(SrcFile, Buffer, SizeOf(Buffer), BytesRead);
if BytesRead > 0 then
begin
BlockWrite(DestFile, Buffer, BytesRead, BytesWritten);
if BytesRead <> BytesWritten then
raise Exception.Create('Error copying file')
else
begin
TotalRead := TotalRead + BytesRead;
ProgressBar1.Position :=ProgressBar1.position+1;
application.ProcessMessages;
end;
end
until BytesRead = 0;
except
Erase(DestFile);
raise;
end;
finally
CloseFile(DestFile);
// Close the destination file.
end;
finally
CloseFile(SrcFile);
// Close the source file.
end;
lv_file.Items.SubItems.Add('完成');
ProgressBar2.StepIt;
ProgressBar2.Update;
end;
application.MessageBox('复制完成!!','提示',mb_ok);
StatusBar1.Panels.Items[1].Text:='';
end;
end;