SPECIAL OFFER        Order and save right now!
20% off with the 729824315 dicscount code for Ultimate Pack and any another product for Delphi from Greatis Programming!

⤷ Find out total size of directory

You should specify a directory. After that, you should find all files in this directory by recursion. You should add to the total size the size of each found file.

procedure TForm1.Find(Str: string);
var
  MySearch: TSearchRec;
  FindResult: Integer;
begin
  FindResult:=FindFirst(Str+'\*.*', 
                        faArchive+faHidden+
                        faAnyFile+faVolumeID+
                        faSysFile+faReadOnly+faDirectory,
                        MySearch);
  while FindResult=0 do
  begin
    if (MySearch.Attr=faDirectory) and 
       (MySearch.Name<>'.') and 
       (MySearch.Name<>'..') then
      Find(Str+'\'+MySearch.Name)
    else
      TotalSize:=TotalSize+MySearch.Size;
    FindResult:=FindNext(MySearch);
  end;
  FindClose(MySearch);
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  TotalSize:=0;
  if Length(Edit1.Text)>0 then
  begin
    Find(Edit1.Text);
    Label2.Caption:='Total size = '+IntToStr(TotalSize);
  end;
end;

procedure TForm1.Button2Click(Sender: TObject);
var
  St: string;
begin
  St:='c:\';
  if SelectDirectory(St, [], 0) then
    Edit1.Text:=St;
end;
Related components
TFileSearch
TFolderMonitor
TFileVersion
More for developers
Databases for Amazon Associates
Amazon Categories
Amazon Nodes