下面這個程序是用來拷整個目錄的,其中加入了進度條的顯示,ok嗎?
var
p:integer;
function TForm1.CopyDir(const vSrcPath, vDestPath: AnsiString;
vOverwrite: Boolean=true): Boolean;
var
r: TSearchRec;
s, d: AnsiString;
ns, nd: AnsiString;
begin
try
try
result := false;
s := IncludeTrailingPathDelimiter(vSrcPath);
d := IncludeTrailingPathDelimiter(vDestPath);
if not ForceDirectories(d) then
Exit;
if FindFirst(s + '*.*', faAnyFile, r) = 0 then
begin
repeat if (r.Name <> '.') and (r.Name <> '..') then
begin
ProgressBar1.Position := p;
inc(p,r.Size);
ns := s + r.Name;
nd := d + r.Name;
if (r.Attr and faDirectory) = faDirectory then
begin
if not ForceDirectories(nd) then
Exit;
CopyDir(ns, nd);
end
else
begin
if FileExists(nd) and (not vOverwrite) then
Continue;
CopyFile(PChar(ns), PChar(nd), false) ;
end;
end;
until FindNext(r) <> 0;
result := true;
end;
except on e: Exceptiondo
result := false;
end;
finally
FindClose(r);
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
count:=getdirsize('D:/music');
ProgressBar1.Max :=count;
p:=0;
CopyDir('D:/music','e:/music');
ShowMessage('ok');
end;
公開答案