下面的代码速度还可以。
procedure TForm1.Button1Click(Sender: TObject);
procedure PathSize(var MySize : Integer; const AnyFile:String);
var
Found:integer;
SearchResult:TSearchRec;
begin
Found:=FindFirst(AnyFile+'/*.*',faAnyFile,SearchResult);
while Found=0 do begin
if (SearchResult.Name<>'.')and(SearchResult.Name<>'..')and(SearchResult.Attr=faDirectory) then begin
PathSize(MySize,AnyFile+'/'+SearchResult.Name);
end else begin
MySize:=MySize+SearchResult.Size;
end;
Found:=FindNext(SearchResult);
end;
if (SearchResult.Name<>'.')and(SearchResult.Name<>'..') then FindClose(SearchResult);
end;
var
i:Integer;
begin
i:=0;
PathSize(i,'c:');
button2.Caption:=inttostr(i);
end;