转自大富翁论谈的weicong大侠
function getdirsize (dir: string; subdir: boolean): longint;
var rec: TSearchRec;
found: integer;
begin
result:=0;
if dir[length(dir)]<>'\' then dir:=dir+'\';
found:= findfirst(dir+'*.*', faAnyFile, rec);
while found=0 do begin
inc(result, rec.size);
if (rec.Attr and faDirectory > 0) and (rec.Name[1]<>'.') and (subdir=true) then
inc(result, getdirsize(dir+rec.Name, true));
found:=findnext(rec);
end;
findclose(rec);
end; procedure TForm1.Button1Click(Sender: TObject);
begin
label1.Caption:=FloatToStr(getdirsize('e:\download', false)/sqr(1024)) + ' MBytes';
label2.Caption:=FloatToStr(getdirsize('e:\download', true)/sqr(1024)) + ' MBytes';
end;
function getdirsize (dir: string; subdir: boolean): longint;
var rec: TSearchRec;
found: integer;
begin
result:=0;
if dir[length(dir)]<>'\' then dir:=dir+'\';
found:= findfirst(dir+'*.*', faAnyFile, rec);
while found=0 do begin
inc(result, rec.size);
if (rec.Attr and faDirectory > 0) and (rec.Name[1]<>'.') and (subdir=true) then
inc(result, getdirsize(dir+rec.Name, true));
found:=findnext(rec);
end;
findclose(rec);
end; procedure TForm1.Button1Click(Sender: TObject);
begin
label1.Caption:=FloatToStr(getdirsize('e:\download', false)/sqr(1024)) + ' MBytes';
label2.Caption:=FloatToStr(getdirsize('e:\download', true)/sqr(1024)) + ' MBytes';
end;
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货