Вычисление размера каталога
uses FileCtrl;
function DirSize(Dir: string): integer;
var
SearchRec: TSearchRec;
Separator: string;
DirBytes: integer;
begin
Result:=-1;
if Copy(Dir,Length(Dir),1)='\' then
Separator := ''
else
Separator := '\';
if FindFirst(Dir+Separator+'*.*',faAnyFile,SearchRec) = 0 then
begin
if FileExists(Dir+Separator+SearchRec.name) then
DirBytes := DirBytes + SearchRec.Size
else
if DirectoryExists(Dir+Separator+SearchRec.name) then
begin
if (SearchRec.name<>'.') and (SearchRec.name<>'..') then
DirSize(Dir+Separator+SearchRec.name);
end;
while FindNext(SearchRec) = 0 do
begin
if FileExists(Dir+Separator+SearchRec.name) then
DirBytes := DirBytes + SearchRec.Size
else
if DirectoryExists(Dir+Separator+SearchRec.name) then
begin
if (SearchRec.name<>'.') and (SearchRec.name<>'..') then
DirSize(Dir+Separator+SearchRec.name);
end;
end;
end;
FindClose(SearchRec);
Result:=DirBytes;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
DirBytes: integer;
begin
DirBytes := DirSize('c:\windows');
Form1.Label1.Caption := IntToStr(DirBytes);
end;
|
|