Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Sonstige Fragen zu Delphi (https://www.delphipraxis.net/19-sonstige-fragen-zu-delphi/)
-   -   Delphi Ordnergröße ermitteln (https://www.delphipraxis.net/139927-ordnergroesse-ermitteln.html)

delphi-n 8. Sep 2009 18:20


Ordnergröße ermitteln
 
Hi!

Ich möchte eine Ordnergröße ermittel, und diese in einer Variablen speichern (möglichst genau, z.B.: 2.371.182.592 Bytes )

Nun gibt es diese Funktion:
Delphi-Quellcode:
function GetFolderSize(Path: string): string;
var
  f: TSearchRec;
  tmp: Int64;
const
  sFormat = '%.2n MB';
begin
  tmp := 0;
  Path := IncludeTrailingPathDelimiter(Path);
  if DirectoryExists(path) then
  begin
    FindFirst(Path + '*.*', faAnyFile, f);
    repeat
      if (f.Attr and FILE_ATTRIBUTE_DIRECTORY = 0) then
        tmp := tmp + f.Size;
    until FindNext(f) <> 0;
    FindClose(f);
  end;
  Result := Format(sFormat, [(tmp / 1024) / 1024]);
end;
allerdings, kapier ich nicht, wie ich das jetzt in eine var bekomme (wie gesagt, möglichst genau)

Vielen Dank für eure Antworten :thumb:

himitsu 8. Sep 2009 18:26

Re: Ordnergröße ermitteln
 
Mit etwas überlegen könnte man vermutlich drauf kommen, daß in tmp die Größe in Byte drinsteht,

also ändert man den Result-Typ erstmal von String nach Int64
und läßt die Umwandlung von Integer (tmp) nach String (Result := Format...) weg und git direkt die Größe zurück.



Oder du veränderst einfach den Format-String und änderst passend dazu die dortige Berechnung.

delphi-n 8. Sep 2009 18:42

Re: Ordnergröße ermitteln
 
Delphi-Quellcode:
tmp: Int64;
das ist doch schon Int64(?)

Und was soll man statt
Delphi-Quellcode:
Result := Format(sFormat, [(tmp / 1024) / 1024]);
schreiben?

Vielleicht kannst du das mal richtig verändert posten. Ich kann mir da irgendwie nichts vorstellen :gruebel:

Luckie 8. Sep 2009 20:11

Re: Ordnergröße ermitteln
 
Guck dir mal in einem Tutorial oder Buch an, was Funktionen sind und wie sie funktionieren.


Alle Zeitangaben in WEZ +1. Es ist jetzt 19:10 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