Einzelnen Beitrag anzeigen

DieDolly

Registriert seit: 22. Jun 2018
2.175 Beiträge
 
#7

AW: Ordnergröße ermitteln

  Alt 17. Dez 2023, 14:55
Danke für die Antworeten. Ich habe mir den Code aus JclUtils genommen und angepasst.
Delphi-Quellcode:
function GetDirectorySize(const Path: string): Int64;
 function RecurseFolder(const Path: string): Int64;
 var
  F: TSearchRec;
  R: Integer;
  TempSize: TWin32FileAttributeData;
 begin
  Result := 0;
  R := System.SysUtils.FindFirst(Path + '*.*', faAnyFile, F);
  if R = 0 then
   try
    while R = 0 do
     begin
      if (F.Name <> '.') and (F.Name <> '..') then
       begin
        if (F.Attr and faDirectory) = faDirectory then
         Inc(Result, RecurseFolder(Path + F.Name + '\'))
        else
         begin
          TempSize.nFileSizeLow := F.FindData.nFileSizeLow;
          TempSize.nFileSizeHigh := F.FindData.nFileSizeHigh;
          Inc(Result, TempSize.nFileSizeHigh shl 32 + TempSize.nFileSizeLow);
         end;
       end;
      R := System.SysUtils.FindNext(F);
     end;
    if R <> ERROR_NO_MORE_FILES then
     Abort;
   finally
    System.SysUtils.FindClose(F);
   end;
 end;

begin
 if not DirectoryExists(ExcludeTrailingBackslash(Path)) then
  Result := -1
 else
  try
   Result := RecurseFolder(IncludeTrailingBackslash(Path))
  except
   Result := -1;
  end;
end;
  Mit Zitat antworten Zitat