Rychlejší funkce na zjištění velikosti adresáře

Vítáme všechny návrhy na nové funkce a vylepšení programu Altap Salamander. Pro každý návrh prosím vytvořte samostatný příspěvek.
burianvlastimil
Posts: 1
Joined: 20 Nov 2014, 09:04

Rychlejší funkce na zjištění velikosti adresáře

Post by burianvlastimil »

Kdyz v Delphi pouziju nasledujici funkci, vyhodnoceni Program Files trva 3 sekundy, Salamanderu to trva 20 sekund. Jsem si vědom, že Salamander vyhodnocuje i velikost komprimovanou, ale že by to měl být takový overhead... nevím, zhodnoťte sami.


function DirectorySize(DirPath: string): Int64;

var
SearchItem: TSearchRec;
ErrorCode: Integer;

begin
Result := 0;

if not DirectoryExists(DirPath) then
raise Exception.Create('Invalid path: ' + sLineBreak + DirPath);

DirPath := IncludeTrailingPathDelimiter(DirPath);

ErrorCode := FindFirst(DirPath + '*.*', faAnyFile, SearchItem);
try

while ErrorCode = 0 do begin

if SearchItem.Attr and faDirectory = 0
then Result := Result + SearchItem.Size
else if (SearchItem.Name <> '.') and (SearchItem.Name <> '..')
then Result := Result + DirectorySize(DirPath + SearchItem.Name);

ErrorCode := FindNext(SearchItem);

end;

finally
FindClose(SearchItem);
end;
end;
User avatar
AD7
Posts: 566
Joined: 28 Jan 2006, 16:21

Re: Rychlejší funkce na zjištění velikosti adresáře

Post by AD7 »

A jak dlho počíta veľkosť toho istého adresára Explorer?
Post Reply