// Hiermit kann man die Größe von Verzeichnissen bestimmen.


// Getestet mit D4 unter XP

function FLR_Sizex(FLR: string; SubFolder: boolean): extended; 
var sr: TWin32FindData; 
  h: THandle; 
begin 
  result := 0; 
  if ansilastchar(FLR) <> '\' then FLR := FLR + '\'; 
  h := FindFirstFile(PChar(FLR + '*'), sr); 
  if h <> INVALID_HANDLE_VALUE then 
    repeat 
      if (sr.dwFileAttributes and FILE_ATTRIBUTE_DIRECTORY > 0) 
        and SubFolder 
        then begin 
        if (string(sr.cFileName) <> '.') and (sr.cFileName <> '..') then 
          result := Result + FLR_Sizex(FLR + sr.cFileName, True); 
      end else 
        result := result + ((sr.nFileSizeHigh * MAXDWORD) 
          + sr.nFileSizeLow); 
      application.processmessages; 
      if application.terminated then break; 
    until Findnextfile(h, sr) = false; 
  windows.FindClose(h); 
end; 
 
 
procedure TForm1.Button1Click(Sender: TObject); 
var smm: extended; 
begin 
  screen.cursor := crHourGlass; 
  smm := FLR_Sizex('c:\windows', True); 
  label1.caption := formatfloat('#,##0 Byte', smm); 
  smm := smm / 1024; 
  label2.caption := formatfloat('#,##0.0 KB', smm); 
  smm := smm / 1024; 
  label3.caption := formatfloat('#,##0.00 MB', smm); 
  smm := smm / 1024; 
  label4.caption := formatfloat('#,##0.000 GB', smm); 
  screen.cursor := crDefault; 
end; 


 

Zugriffe seit 6.9.2001 auf Delphi-Ecke