Get Folder Contents and Size

I want to put a button on a form and when I click it I want it to give me the properties of a folder. IE: Size in Megabytes of the folder and how many object are in the folder: IE other folders and files.

thanks,
mjbcomp
mjbcompAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

compeagerCommented:
procedure TForm1.Button1Click(Sender: TObject);
var
  TotFolder: Integer;
  TotFile: Integer;
  TotSize: DWORD;

  procedure ScanPath(Path: string);
  var
    F: TSearchRec;
  begin
    try
      if FindFirst(Path + '*.*', faAnyFile, F) = 0 then
        repeat
          if (F.Name <> '.') and (F.Name <> '..') then
          begin
            if F.Attr and faDirectory <> 0 then
            begin
              Inc(TotFolder);
              ScanPath(Path + F.Name + '\');
            end else Inc(TotFile);

            Inc(TotSize, F.Size);
          end;
        until FindNext(F) <> 0
      else
        begin
          TotFile := 0;
          TotSize := 0;
        end;
    finally
      FindClose(F);
    end;
  end;

begin
  TotFolder := 0;
  TotFile := 0;
  TotSize := 0;
  ScanPath('C:\');
  ShowMessage(Format('%d folders %d files, %d MB (%d bytes)',
    [TotFolder, TotFile, TotSize div (1024 * 1024), TotSize]));
end;

Do not forget to add '\' to the end of the path, example: do not write ScanPath('C:\Windows') instead write ScanPath('C:\Windows\')...

That's it...

Ofcourse this is a game but you should be more generous to the programmers :(
Only 5 points LOL, if one waited one more day, they would have got it...
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
mjbcompAuthor Commented:
Thanks for the effort. However this example does not correctly count the number of FILES or the correct amount of Hard Drive Space Used.

I am using Delphi 3.0 Professional running on Windows NT.

Any suggestions? :)

mjbcomp
0
xpherCommented:
listening
0
Bootstrap 4: Exploring New Features

Learn how to use and navigate the new features included in Bootstrap 4, the most popular HTML, CSS, and JavaScript framework for developing responsive, mobile-first websites.

mjbcompAuthor Commented:
What was that comment for?
:<
0
craig_capelCommented:
yes please do tell.....


whats this for "listening" ?????????
0
xpherCommented:
it is a way to keep in touch with the thread. just checking the box for email notification is no good if question gets answered. you can see it through lots os questions throughout EE

xpher
0
gandalf_the_whiteCommented:
listening...
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.