Delphi Tips&Tricks News   Tips   .NET Software   VCL Software   Search   Contacts
Ultimate Pack Special Offer!


Share this page

Follow us
LinkedIn Blogspot Twitter Facebook

Related products
Ultimate Pack  hot!
iGrid Plotter  new!
Image Editor
Runtime Fusion
Form Designer
Object Inspector
Print Suite Pro
Commented Image
Delphi Toys
WinDowse
Delphi Bonus
TMS Scripter Studio
Form Designer VB
Form Designer .NET
Print Suite .NET
Gradient Controls .NET  new!

Related links
Win32.hlp online version
MegaDetailed.NET
Delphi to C#

Special
Free Software Promotion
Offers for Resellers

Hobby projects
cdtrrracks.com
books.storrre.com
in3steps.com
sovietphillumeny.com

Find out total size of directory - Files & folders - Tips & Tricks - Greatis Delphi Pages

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 topics
Delete all files within directory
Recognize whether Word is installed
Remove all files from directory

For more
Delphi Help

Download source