AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Zurück Delphi-PRAXiS Projekte Does It Fit? Ein nützliches Brenntool
Thema durchsuchen
Ansicht
Themen-Optionen

Does It Fit? Ein nützliches Brenntool

Ein Thema von phlux · begonnen am 9. Aug 2007 · letzter Beitrag vom 17. Okt 2007
Antwort Antwort
hathor
(Gast)

n/a Beiträge
 
#1

Re: Does It Fit? Ein nützliches Brenntool

  Alt 10. Aug 2007, 12:51
Ich habe eine DIRSIZE-Funktion gefunden, die identische Werte wie der Explorer anzeigt:

Delphi-Quellcode:
...
var TotalSize: Int64; //global
...
function AddThouSeps (const S: string): string;
var
    LS, L2, I : Integer;
    Temp : string;
begin
    result := S ;
    LS := Length (S);
    if LS <= 3 then exit ;
    L2 := (LS - 1) div 3;
    Temp := '';
    for I := 1 to L2 do
            Temp := ThousandSeparator + Copy (S, LS - 3 * I + 1, 3) + Temp;
    Result := Copy (S, 1, (LS - 1) mod 3 + 1) + Temp;
end;

function DirSize(Path: string; ScanLabel, SizeLabel: TLabel): Int64;

{ func to return the total number of bytes found in a directory. }
{ You can pass 2 TLabels for a progress while scanning:
  ScanLabel: will display the current path being scanned
  SizeLabel: will display the total size so far counted.
  If you don't want to use either Labels, pass nil to both. You
  can still use returned value to read the total size. Example:
  (For Delphi 4/5)
  TotalSize := 0;
  Label1.Caption := IntToStr(DirSize('C:\Windows', nil, nil)) + ' bytes';
  (For Delphi 3)
  TotalSize := 0;
  Label1.Caption := FloatToStr(DirSize('C:\Windows', nil, nil)) + ' bytes';
  (It is a little faster this way.)
  Note: you MUST initialize the global TotalSize variable to 0 before
  using this function. }

var
  Res: Integer;
  SR: TSearchRec;
begin
  Result := TotalSize;
  if Copy(Path, Length(Path), 1) <> '\then
    Path := Path + '\';
  if not DirectoryExists(Path) then
    begin
      MessageDlg('Directory does not exist: ' + Path, mtError, [mbOK], 0);
      Exit;
    end;
  if ScanLabel <> nil then
    begin
      ScanLabel.Caption := 'Scanning ' + Path;
      ScanLabel.Update;
    end;
  Res := FindFirst(Path + '*.*', faAnyFile, SR);
  try
    while Res = 0 do
      begin
        if (SR.Name [1] <> '.') and (SR.Name [1] <> '..') then
          begin
            if ((SR.Attr and faDirectory) <> 0) then
              DirSize(Path + SR.Name + '\', ScanLabel, SizeLabel)
            else
              TotalSize := TotalSize + SR.Size;
          end;
        Res := FindNext(SR);
        if SizeLabel <> nil then
          begin
            {$IFDEF Delphi3Below}
            SizeLabel.Caption := 'Total size: ' + FloatToStr(TotalSize) + ' bytes';
            {$ELSE}
            SizeLabel.Caption := 'Total size: ' + IntToStr(TotalSize) + ' bytes';
            {$ENDIF}
            SizeLabel.Update;
          end;
      end;
  finally
    FindClose(SR);
  end;
  Result := TotalSize;
end;

//Aufruf - Beispiel:
//TotalSize:=0; Label1.Caption := FloatToStr(DirSize('C:\Windows', nil, nil)) + ' Bytes';

//oder formatiert:
//Label1.Caption := AddThouSeps(FloatToStr(DirSize('C:\Windows', scanlabel1, sizelabel1))) + ' Bytes';
  Mit Zitat antworten Zitat
Antwort Antwort


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 05:12 Uhr.
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz