Forum
Grundkurs
»Introduktion
»Snabbguide
»Komponenter
»Händelser
»Strängar
»Räkna med Delphi »Egna
typer
»Selektion
»Iteration
»Menyer
»Funktioner
»Arraystrukturer
Tips & Tricks
»Nya tips
»Blandat
»Databaser
»Filer
»Forms
»Grafik
»Internet
»Komponenter
»Matematik
»Multimedia
»Objekt/ActiveX
»Skrivare
»Strängar
»System
»Mest lästa tips
Artiklar
»Delphi och ADO
»Bygga en DLL
»Skapa en enkel rapport
»Hantera registret
»Enheter, units
»Klassen TCanvas
»Använd LookUp Controls
Nya
tips
Lägg
till tips
Delphilänkar
Gästbok
|
|
Returnera mappstorlek
|
Kategori: Filer
Inlagt: 2005-07-17
Läst: 1317
Inlagt av: Staffan Berg
|
Beskrivning |
Använd detta exempel för att returnera den totala storleken på alla filer i en specifik mapp.
|
Kod |
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;
|
|
|