Autor Beitrag
Calyptus
ontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic starofftopic star
Beiträge: 386

Win Xp Prof
D3, D6 Pers, D7 Ent
BeitragVerfasst: Sa 06.11.04 01:00 
Hallo!

Gibt es eine Fuktion o.ä. die mir die Größe eines Ordners gibt?


Moderiert von user profile iconTino: Topic aus Sonstiges verschoben am Mo 08.11.2004 um 12:54

_________________
Luft- und Raumfahrtechnik an der Uni Stuttgart
BenBE
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 8721
Erhaltene Danke: 191

Win95, Win98SE, Win2K, WinXP
D1S, D3S, D4S, D5E, D6E, D7E, D9PE, D10E, D12P, DXEP, L0.9\FPC2.0
BeitragVerfasst: Sa 06.11.04 01:21 
Wozu braucht man dazu eine Funktion? Ein Ordner ist IMMER 0 Byte groß. (wirklich)

Aber falls du den Inhalt meinst: Alle Dateien drin suchen und die Dateigrößen zusammenaddieren. Siehe FindFirst, FindNext und FindClose, sowie "rekursive Suche".

_________________
Anyone who is capable of being elected president should on no account be allowed to do the job.
Ich code EdgeMonkey - In dubio pro Setting.
Harry M.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 754

Win 2000, XP
D2005
BeitragVerfasst: Sa 06.11.04 04:35 
ich habe es aber nicht getestet solte aber funktionieren
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
function GetDirSize(dir: string; subdir: Boolean): Longint;
var
  rec: TSearchRec;
  found: Integer;
begin
  Result := 0;
  if dir[Length(dir)] <> '\' then dir := dir + '\';
  found := FindFirst(dir + '*.*', faAnyFile, rec);
  while found = 0 do
  begin
    Inc(Result, rec.Size);
    if (rec.Attr and faDirectory > 0) and (rec.Name[1] <> '.') and (subdir = True) then
      Inc(Result, GetDirSize(dir + rec.Name, True));
    found := FindNext(rec);
  end;
  FindClose(rec);
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  label1.Caption := FloatToStr(GetDirSize('e:\download', False) / Sqr(1024)) + ' MBytes';
  label2.Caption := FloatToStr(GetDirSize('e:\download', True) / Sqr(1024)) + ' MBytes';
end;


Moderiert von user profile iconChristian S.: Code- durch Delphi-Tags ersetzt.
Calyptus Threadstarter
ontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic starofftopic star
Beiträge: 386

Win Xp Prof
D3, D6 Pers, D7 Ent
BeitragVerfasst: Sa 06.11.04 13:13 
@User-Xy2004: Tut so weit, aber wenn die Ordner zu groß werden (so ca 1Gbyte) kommt so was raus:
-515,454384803772 MBytes (hier war der Ordner ca 20Gbyte groß).

Wie könnte ich es hinbekommen das es auch große Ordner richtig anzeigt?

_________________
Luft- und Raumfahrtechnik an der Uni Stuttgart
wulfskin
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1349
Erhaltene Danke: 1

Win XP
D5 Pers (SSL), D2005 Pro, C, C#
BeitragVerfasst: Sa 06.11.04 13:33 
Tja,

das liegt wohl daran, dass die Größe von LongInt nicht mehr ausreicht um die Größe darzustellen, deshalb springt er in den negative Bereich (overflow). Wenn du das wirklich brauchst, dann musst du wohl mit dem Typ Int64 arbeiten.
Allerdings solltest du dann auch beachten, dass der Typ TSearchRec.Size auch nur die Größen in der Höhe MaxIntValue darstellen kann. Deshalb solltest du dann auch konsequent sein und die API-Funktionen benutzen um die Größe der Dateien auch vom Typ Int64 zu bekommen.

Gruß Hape!

_________________
Manche antworten um ihren Beitragszähler zu erhöhen, andere um zu Helfen.
Calyptus Threadstarter
ontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic starofftopic star
Beiträge: 386

Win Xp Prof
D3, D6 Pers, D7 Ent
BeitragVerfasst: Sa 06.11.04 13:52 
wulfskin hat folgendes geschrieben:
Allerdings solltest du dann auch beachten, dass der Typ TSearchRec.Size auch nur die Größen in der Höhe MaxIntValue darstellen kann. Deshalb solltest du dann auch konsequent sein und die API-Funktionen benutzen um die Größe der Dateien auch vom Typ Int64 zu bekommen.


Danke! Aber: Wie mache ich das?

_________________
Luft- und Raumfahrtechnik an der Uni Stuttgart
Luckie
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: Sa 06.11.04 14:50 
So zum Beispiel:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
function GetFileSize(szFile: PChar): Int64;
var
  fFile: THandle;
  wfd: TWIN32FINDDATA;
begin
  result := 0;
  if not FileExists(szFile) then exit;
  fFile := FindFirstfile(pchar(szFile),wfd);
  if fFile = INVALID_HANDLE_VALUE then exit;
  result := (wfd.nFileSizeHigh*(Int64(MAXDWORD) + 1))+wfd.nFileSizeLow;
  windows.FindClose(fFile);
end;
Calyptus Threadstarter
ontopic starontopic starontopic starontopic starhalf ontopic starofftopic starofftopic starofftopic star
Beiträge: 386

Win Xp Prof
D3, D6 Pers, D7 Ent
BeitragVerfasst: Sa 06.11.04 15:32 
Hey cool. Jetzt gehts :D :D :D

_________________
Luft- und Raumfahrtechnik an der Uni Stuttgart
BenBE
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 8721
Erhaltene Danke: 191

Win95, Win98SE, Win2K, WinXP
D1S, D3S, D4S, D5E, D6E, D7E, D9PE, D10E, D12P, DXEP, L0.9\FPC2.0
BeitragVerfasst: Sa 06.11.04 17:01 
Der SearchRecord von FindFirst\FindNext und FindClose gibt den FindData-Record von Windows bereits zurück.

Die Größe kann daher auch einfach mit
ausblenden Delphi-Quelltext
1:
FileSize := Int64(SR.FindData.nFileSizeHigh) shl 32 + SR.FindData.nFileSizeLow;					

berechnet werden. Zu beachten ist, dass die DWORD-Felder als Int64 gecastet werden muss.

Dann funktioniert auch die erste Routine mit sehr großen Verzeichnissen.

_________________
Anyone who is capable of being elected president should on no account be allowed to do the job.
Ich code EdgeMonkey - In dubio pro Setting.