Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   Trucos (https://www.clubdelphi.com/foros/forumdisplay.php?f=52)
-   -   Conocer el espacio que ocupa un directorio (https://www.clubdelphi.com/foros/showthread.php?t=80623)

dec 30-06-2006 23:05:49

Conocer el espacio que ocupa un directorio
 
Si necesitamos calcular el tamaño que nos ocupa un directorio, podemos hacer lo siguiente:

Código:

void __fastcall TForm1::Button1Click(TObject *Sender)
{
  TSearchRec sr;
  double tamanyo=0;
  int iAttributes = 0;

  if (FindFirst("c:\\windows\\*.*", iAttributes, sr) == 0)
  {
    tamanyo += sr.Size;
    while (FindNext(sr) == 0)
      tamanyo += sr.Size;
  }
  FindClose(sr);
  ShowMessage(tamanyo);
}

Si este directorio contiene otros subdirectorios, y también queremos conocer el espacio que nos ocupan en disco...

Código:

#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
double size=0;

//---------------------------------------------------------------------------
double tamanyo(AnsiString Path)
{
TSearchRec R;
int F = FindFirst(Path + "\\*", faAnyFile, R);
while(F==0)
{
if(R.Name != "." && R.Name != "..")
{
if(R.Attr == faDirectory)
tamanyo(Path + "\\" + R.Name);
else
size+= R.Size;
}
F = FindNext(R);
}
FindClose(R);
return size;
}

__fastcall TForm1::TForm1(TComponent* Owner): TForm(Owner)
{
Label1->Caption = AnsiString(tamanyo("c:\\mirc"));
}
//---------------------------------------------------------------------------



La franja horaria es GMT +2. Ahora son las 10:36:17.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi