Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Object-Pascal / Delphi-Language (https://www.delphipraxis.net/32-object-pascal-delphi-language/)
-   -   Delphi Need hlp with directory size (https://www.delphipraxis.net/172486-need-hlp-directory-size.html)

WojTec 6. Jan 2013 18:34

Delphi-Version: 2010

Need hlp with directory size
 
Delphi-Quellcode:
var
  Dir: string;
  Rec: TSearchRec;
begin
  Result := 0;

  Dir := IncludeTrailingPathDelimiter(ADirectory);
  if FindFirst(Dir + AMask, faAnyFile or faDirectory, Rec) = 0 then
  try
    repeat
      if (Rec.Attr and faDirectory) = faDirectory then
      begin
        if (Rec.Name <> '.') and (Rec.Name <> '..') then
          Result := Result + GetDirectorySize(Dir + Rec.Name)
        ;
      end
      else
        Result := Result + GetFileSize(Dir + Rec.Name);
      ;
    until FindNext(Rec) <> 0;
  finally
    FindClose(Rec);
  end;
end;
This is my function. It working well, when need to get complete folder size, but for example if I set mask to "*.mp4", it returns 0. Test folder contain 0 files and many folders, each one contain files (in each one is minimum 1 MP4 file). What's wrong with this code?

DeddyH 6. Jan 2013 18:42

AW: Need hlp with directory size
 
I suppose the directories do not end on ".mp4", so your mask does not match.

WojTec 6. Jan 2013 18:46

Re: Need hlp with directory size
 
You are correct. I know. But how (where) to apply this mask?

DeddyH 6. Jan 2013 18:50

AW: Need hlp with directory size
 
You should set the internally used mask to *.* and check the search result to the mask of interest. I wrote a component which does it this way, in case of interest you can find it on Torry.

WojTec 6. Jan 2013 19:56

Re: Need hlp with directory size
 
Nice component, I glanced on it, found what I needed and, yeah, I did it! :D


Alle Zeitangaben in WEZ +1. Es ist jetzt 06:33 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz